Loop troubles

In the following code, for some reason, i have to loop it 52 times (26 x 2) inorder to have it go through 26 iliterations. Anyone know why? Here is the code:

namespace CompilerTester
{
    class Tester
    {
        static void Main(string[] args)
        {
            CodeStack Code = new CodeStack();
            Code.EnqueueCommand(CellCommands.AddToCell, 65);

            for (int i = 0; i < 52; ++i)
            {
                Code.EnqueueCommand(CellCommands.OutputCommand, 0);
                Code.EnqueueCommand(CellCommands.AddToCell, 1);
            }

            Console.WriteLine(Code.RunCode());
            Console.ReadLine();
        }
    }
}

This is from an side project to test a interpreter for a set of simple commands. This should add 65 to the cell, and then output the character for the value of the cell, increase it by one, and do output it again, 26 times. Changing the for loop from "for (int i = 0; i < 52; ++i)" to "for (int i = 0; i < 26; ++i)" ends up with 13 letters or 1/2 of the alphebet with the 52 outputs the whole thing. Any reason for this seemgly glitch (I am, btw, using a Microsoft Visual C# 2005 Express Edition Beta)
cimnik029Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AaronReamsCommented:
uh, my guess would be 26 lower case letters + 26 upper case letters = 52 total iterations.  am i missing something?
0
cimnik029Author Commented:
no, its only to get the capital letters:
ABCDEFGHIJKLMNOPQRSTUVWXYZ <- thats the exact output.

Plus thats not possible as there are a handful of characters that rest between the caital Z and the lowercase a
0
AaronReamsCommented:
hmmm, good point... ascii 91-96 aren't letters.  well i just took a wild guess.  i'll have to think about it some more.  good luck.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

sendmeblahCommented:
What happens when you try a while loop?

int i=0
while (i < 26)
{
   Code.EnqueueCommand(CellCommands.OutputCommand, 0);
   Code.EnqueueCommand(CellCommands.AddToCell, 1);
   i++
}

Do you have a hyperthreaded machine?  I have seen weird things happen in if statements concerning the ++ operator in VS 2003.
0
cimnik029Author Commented:
same problem persists. and no i dont have a hyperthreaded machine.
0
TheAvengerCommented:
I didn't find the class CodeStack in the VS 2005 Beta 1 documentation so I suppose it's some code you wrote, or? What does it do? I suppose the problem is inside the method EnqueueCommand
0
cimnik029Author Commented:
i wonder. should have posted code. here is the summerized version

CommandType in an enum, Command is a struct to hold a command (command function and paramater)

class CodeStack
    {
        public Queue Code;

        public void EnqueueCommand(CellCommands CommandType, int Value)
        {
            Command NewCommand = new Command();
            NewCommand.CommandType = CommandType;
            switch ((int)CommandType)
            {
                case 1: // NextCellCommand;
                    NewCommand.ACommand = new NextCellCommand();
                    break;
                case 2: // PreviousCellCommand
                    NewCommand.ACommand = new PreviousCellCommand();
                    break;
                case 3: // AddToCellCommand
                    NewCommand.ACommand = new AddToCellCommand();
                    break;
                case 4: // SubtractFromCellCommand
                    NewCommand.ACommand = new SubtractFromCellCommand();
                    break;
                case 5: // JumpCommand
                    NewCommand.ACommand = new JumpCommand();
                    break;
                case 6: // OutputCellCommand
                    NewCommand.ACommand = new OutputCommand();
                    break;
            }
            NewCommand.ACommand.Table = MemoryTable;
            NewCommand.CommandValue = Value;
            Code.Enqueue(NewCommand);
        }
0
cimnik029Author Commented:
i figured it out! what a dumn question!

i had a loop statment in my code look like this

for (int i = 0; i < Code.Count; ++i)

Code is a queue, and in every iliteration, as i went up, code.count went down. Therefore, when dealing with 8 elemenst, it would stop half way as i and code.count would end up both equaling 4 half way through and quiting, creating the illusion of a loop at the beginning that needed to be run 2 times as much. I figured out the error when steping through the code showed that all the commands got stored, but only half, with the inter loop counter stoping half way through. I changed the code to this and it works.

int LoopCount = Code.Count;
for (int i = 0; i < LoopCount; ++i)
0
SRigneyCommented:
It's not a dumb question, things like that happen.  I hope that this experience shows you that you should post all of the code in question.  The code you posted does not contain the loop wth Code.Count in it, so the experts here didn't have the opportunity to find it and help you.

Congratulations on getting the problem solved.
0
moduloCommented:
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.