"for" loops (was Re: C++ vs. Modula2)

stepanek/cs assoc abcscagz at csuna.UUCP
Thu Jan 26 11:45:52 AEST 1989


In article <739 at jupiter.iis.UUCP> heiser at iis.ethz.ch (Gernot Heiser) writes:
>
>worst features. C's 'for' is really a 'while' with an initialization clause and
>a designated spot that may contain an incrementation clause. What I consider a
>"real" 'for' (as opposed to the while/repeat/loop family) is a construct that
>executes a specific number ot times, the iteration count being determined
>BEFORE the processing of the body starts. This is what is really needed most of
>the time in numerical programs. The other cases are exactly what while/repeat/
>loop constructs are for.


Actually, C's "for" can be duplicated EXACTLY by C's "do ... while" loops.
Consider:

    for (i = 0; i <= 17; ++i)
    {
        stuff();
        more_stuff();
    }

versus:

    i = 0;
    do {
        stuff();
        more_stuff();
    } while (++i <= 17);


These two iterations are indistinguishable from one another.  The "for" term
in C is totally superfluous and is only included because it makes it look like
languages that have a more "for"-ish "for" statement, like Pascal or Modula.
(I won't even get into Algol's "for" here....)

-- 
Jeff Boeing:  ...!csun.edu!csuna!abcscagz    (formerly tracer at stb.UUCP)
--------------------------------------------------------------------------
"When Polly's in trouble I am not slow  /  It's hip, hip, hip and away I go!"
                            -- Underdog



More information about the Comp.lang.c mailing list