"for" loops (was Re: C++ vs. Modula2)
John Hascall
hascall at atanasoff.cs.iastate.edu
Sat Jan 28 00:38:41 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
^^^^^^
I can't count the number of times this has nailed C novices who have had
experience with other languages (i.e., FORTRAN).
For example:
for ( i=0; i < fn_with_side_effects(x); i++ ) {
blue_dog_moon_up();
}
>the time in numerical programs. The other cases are exactly what while/repeat/
>loop constructs are for.
As far as I can see, the main purpose of C's "for" is to save space,
which is one of C's strengths (to some, probably not to MIS/COBOL
types [oh! sorry, this isn't the misc.jobs.misc C/COBOL-CS/MIS
flamewar?])
John Hascall
ISU Comp Center
More information about the Comp.lang.c
mailing list