Our teacher told us not to use 'break' in loops, too. i dont know about whiles, but it can confuse you (and ignore the meaning of the 'third parameter of for', and make the 'for' loop have more than 1 condition)-
if you 'break' a for loop, so the third parameter of the 'for' will not be called.
for example,
for (int i=0;i<1;i++) break; printf("%d",i);
software will print 0 instead of 1 (if you cut the 'break' word, it will print 1)
maybe thats why he/she said not to use breaks in a for loop.
for's should call the third parameter after every loop, right? but it is not called and it may confuse you (maybe)- did the loop called the third parameter this time or not?
for (int i=0;i<4;i++){if (i==3)break;}
it also 'decides' the condition of the 'for' statement, but you already defined the condition. more than 1 condition? weird and maybe also unreadable, i dont know. it 're-define' the condition of the 'for' loop.
so in the code above, the first condition will never return 'true'.
the loop body is not the place for the condition of the loop body, its like to create x from x, i think. or let x decide things for itself (which is a good thing for humans, but for machines?)
The second parameter should be the
only condition of the loop, and the third should
always be called after the condition returns 'true'.
Shouldn't the 3 parameters
always decide what will be to the loop body? (so the loop body can't change it)
maybe thats why you can't use 'break's in exams.
Isn't it like the 3 parameters are what god decide and the human is the 'loop body'?
the human can't decide by himself what was decided for him (e.g. body color, destiny), its already made. so he'll have to stay with it
forever.
hope i found the right reason for not using it in exams,
pex.
[Edited by - pex22 on December 17, 2004 11:56:01 AM]