for != while

karl at haddock karl at haddock
Sun Sep 7 02:52:00 AEST 1986

pogo!operator (Shannon Nelson) writes:
>... The correct translation of your for loop into a while loop is:
>main() {
>        char *foo = "outer";
>        while (TRUE) {
>                { char *foo = "inner"; }
>                printf(foo);
>                exit(0);
>        }

Oops.  You're right; I forgot about the extra braces.

But as long as we're on the subject, shouldn't the general whilified for be
written "{ e1; while (e2) { statement e3; } }", with the extra pair of braces
surrounding the whole mess?  (Consider "if (e0) for (e1; e2; e3) statement".)

Karl W. Z. Heuer (ima!haddock!karl; karl at, The Walking Lint

More information about the Comp.lang.c mailing list