I don't know if your question should be considered as duplicate but maybe this is the answer:
http://stackoverflow.com/questions/1782263/are-loops-with-and-without-parenthesis-handled-differently-in-c/1782281#1782281
The debugger executes one statement at a time.
I was a bit mistaken in my previous answer. Of course the debugger also executes the loop 4 times. The difference is , that it looks like he exits after one iteration. When I debug the following code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
int r;
for (r = 0;;r++)
if (r == 4)
break;
printf("%i",r);
return 0;
}
the debugger processes the for
line, then the if
line, the for
line again and then highlights the printf
line. So it looks like printf
is going to be executed but in the next step, the debugger highlights the if
line again, then going to for
, thereby increasing r
and then highlighting printf
again.
This is the code I tried in Xcode and it is basically the same behavior as described above (I just added some lines of code in main.m
in a fresh Cocoa application project):
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
int r;
for (r = 0;;r++)
if (r == 4)
break;
return NSApplicationMain(argc, (const char **) argv);
}
Picture with Cocoa application:
So the question is, have you really clicked through the loop step by step and is the loop really exiting after one iteration, or have you just stopped after one iteration?