On Thu, 2010-12-02 at 13:32 -0700, Richard wrote:
In article
<AANLkTi=9NwjfxZvaz2H-btkzt8q-c9ErbpNYW+hMfMe=(a)mail.gmail.com>om>,
Ethan Dicks <ethan.dicks at gmail.com> writes:
for (;;)
;
I don't see how this is an infinite loop requiring reset of the
processor to escape since the condition clause is empty. In fact,
since the condition clause is empty, I'm not even sure its
syntactically valid, but C is strange enough that it may be
syntactically valid but not intuititve.
Oh, it's valid. A C for() loop has the following syntax:
for (initialiser, condition, loop)
Initialiser is run once before the first loop.
Condition is validated at the beginning of the loop. If it is TRUE, then
the loop carries on regardless. If the condition is omitted, it is
assumed to be TRUE.
Loop is executed once for each time the loop completes, at the end of
the loop.
So this:
for (i=0; i<10; i++) {
printf("foo %d\n", i);
}
Is equivalent to:
i=0;
while (i<10) {
printf("foo %d\n", i);
i++;
}
Kernighan & Ritchie "The C Programming Language", Second Edition
"Revised for ANSI C". Page 60, section 3.5, paragraph 4, last line. I'd
reference the ANSI standard, but K&R seemed just as good (and more
accessible) 8^)
TTFN,
--
Phil.
classiccmp at philpem.me.uk
http://www.philpem.me.uk/