If I have the following code, what will the integer "i" be equal to after it executes? Does a loop increment after a break statement?
int i = 0;
for(int foo = 0; foo < 10; foo++,i++){
break;
}
You can actually look this up in the standard. A for loop with a break, by definition, is like a while, goto, as so:
for( init; test; incr){
break;
}
is
init
while(test){
// do things
goto end
incr
}
end:
So, since the break is always executed, it never hts the increment part, and neither foo nor i will be incremented.
Why don't you put a println and see...
I'm going to say it ends up with what you started (i.e., zero -- the increment happens after the code in inside the for executes -- since you break out of it, it never gets to increment).
i?breakexecutes before the update part, soidoesn't change.