for <==> while (an exception)

Ron Natalie <ron> ron at brl-tgr.ARPA
Tue Jul 16 08:25:56 AEST 1985


> Here's another ...
> An infinite "for" loop is given by "for (;;) statement".  The equivalent
> "while" expression is, logically, "while () statement".  As this fails to
> compile, one has to resort to "while (1) statement"; which is less efficient
> in most cases as code is generated to test if "1" equals "0".

MYTH! MYTH! (yeth thailor) most of the popular compilers will evaluate
constant expressions and not test them explicitly.  The 4.2 compiler
even knows enough to tell me that if I don't have an exit from the while(1)
loop, that the further statements are not reached.  It, in fact, generates
the same code for either of the infinite loop cases.

-Ron



More information about the Comp.lang.c mailing list