Very strange loop behavior?

  • Thread starter Thread starter David Veeneman
  • Start date Start date
D

David Veeneman

A project that I have been working on has stopped executing loops correctly.
I can add a simple loop to a class in the project, like this:

for (int i = 0; i < 5; i++)
{
Console.Write(i);
}

The 'for' line will execute, then the 'Console.Write()' line, and the focus
jumps to the 'i++' statement. However, the counter 'i' doesn't increment--
it remains at zero after the 'i++' statement is executed. The 'i < 5' still
evaluates to true, but the program immediately exits the loop, as if 'i' had
reached 5.

Has anyone else come across anything like this? Any suggestions on what it
might be? Thanks

David Veeneman
Foresight Systems
 
Do you have a watch statement that does something with the 'i' variable?
That could be a likely cause. Does the program work correctly if run without
debugging?
 
No, I don't have any watch statements on the code. But I have discovered
that the problem only occurs when I step through the code. When I run it
without breakpoints, it behaves as it should. Any idea what's going on?
Thanks

David Veeneman
Foresight Systems
 
The watch problem is often the cause, since anything done to the variable
during debugging is done on the real thing.

However, if this is really not the case, sounds like a debugger issue. Can
you reproduce this in a new project? Try deleting the dll and recompiling on
your existing project - I wonder if that will fix it.
 
Oddly enough, the problem does not occur in new projects. Deleting the DLL
and PDB didn't solve the problem. I'll keep puzzling over this one. Thanks
for your help.
 
Back
Top