On Thu, 2 Dec 2010, Ethan Dicks wrote:
I think you are imagining it backwards. A for loop
continues *until*
the condition is true. (i > 10 or some such). A _missing_ conditional
test is always false, so the loop test will never satisfy, so the loop
will never exit on its own (which is why a break or a processor reset
is needed to break out of it).
Close.
A for loop will continue *until* the condition is NOT true.
for (i=0; i<10; i++) { /*something*/ . . . }
on the first 10 passes, the condition is true, as i is, indeed, less than
10.
?I've seen
it written as while (1); or while (1) {}.
Those are correct as written, but they
are a different keyword with a
different sense on the test. A while loop continues _as long as_ the
test is true. 1 is never 0, so it's always true.
I have been told many times (someday I'll learn never to believe what I am
told!) that some compilers actually preprocess for's into while's or
vice-versa, before compilation. It is certainly trivial to replace either
one with the other in almost all cases.