for loop flow problems

Hi, any one is there to help me. i have faced a new problem in for loop in Visual Studion 2005 with Visual C++ 2005 and Compiler version 8
i have these statements
int nIndex = 1;

for(; nIndex <3; nIndex++)
cout<<nIndex << ",";
Now actually the loop must run two times and must print 1, 2,
This is very well in win32 console appication written in visual studio 2005 with Visual C++.
But when i run it in an MFC based appication it only prints 1
that is first Initialized and then increment and then condition and body execution.although this is not the actual flow of for loop.
plz help me that what is problem here. is it due to of compiler.
I shal be thankful.
Best Regards
Gul
There is nothing obvious in the code other than possibly the lack of an endl. I have seen cout statements get stuck in the buffer because of this. Although not knowing the code around this loop it may not be an option.

I would suggest running it in debug with break points and stepping through line by line and watching the value of nIndex to make sure it is doing what it is supposed to.
Last edited on
Topic archived. No new replies allowed.