"for" loops (was Re: C++ vs. Modula2)
stepanek/cs assoc
abcscagz at csuna.UUCP
Sun Jan 29 08:38:05 AEST 1989
Hoo boy, did I ever mess up in my last posting.
I forgot that a C "for" loop may be executed zero times.
So, let me rephrase my conviction that a C "for" loop is superfluous
because it can be replaced by an equivalent "while" loop, NOT an
equivalent "do ... while" loop:
for (i = 0; i <= 17; i = sqr(i) + 2)
<stuff>;
versus:
i = 0;
while (i <= 17)
{
<stuff>;
i = sqr(i) + 2;
}
There. I hope I have redeemed myself in the face of my previous blasphemy.
And now that I think about it, it IS nice to have final incrementational
conditions in the loop declaration rather than at the end of the loop-body,
as the "while" case forces you to do.
(Although I do still believe that the initial "statement" field of a
"for" loop is superfluous.)
--
Jeff Boeing: ...!csun.edu!csuna!abcscagz (formerly tracer at stb.UUCP)
--------------------------------------------------------------------------
"When Polly's in trouble I am not slow / It's hup, hup, hup and awaay I go!"
-- Underdog
More information about the Comp.lang.c
mailing list