loops in c
raw at math.arizona.edu
raw at math.arizona.edu
Thu Mar 29 22:39:13 AEST 1990
In article <4543 at daffy.cs.wisc.edu> you write:
>In article <KZB#G{_ at rpi.edu> night at pawl.rpi.edu (Trip Martin) writes:
>| An interesting note that might give some perspective to this issue is how
>| Plus, a little-known language that I'm somewhat familiar with, handles loops.
>| Instead of having both while and do..while forms of loops, it uses one form
>| called cycle. Cycle is an infinite loop. You can then stick exit statements
>| anywhere in the loop (and then can be conditional, with both flavors of tests
>| supported). Conceptually, it's a more general way of handling loops.
>
>This is the second request I've seen for a loop construct that allows an
>exit from anywhere in the loop. Is there something drastically wrong with:
>
>for(;;) {
> <statements>
> if (expr)
> break;
> <statements>
>}
>
>or have I missed something here?
>
>Rick (schaut at garfield.cs.wisc.edu)
The point you missed Rick, is that this is a _perversion_ of a for loop. The
same nastiness could be written with a while or a do...while. My point is
the cycle statement above and the the loop ... test ... repeat I talked about
are the **NATUAL** looping structures in their respective languages. These
constructs allow a more natural structure to a program IMNSHO and are _easier_
to use.
If I saw C code like the above for ... if then break, I would be tempted to
shoot the person and/or persons responsible. IMO the loop should be rewritten.
The reason that code like the above is written is because to many people it is
a natural way to do it. You have to be _trained_ *NOT* to author code like
that.
So lets make it easier on all. Demand a loop {stmnt} test {stmnt} repeat
in ANSI C!!!!!!!!!!!!!!!!!!!!!!!!!!!
Richard Walter
-------------------------------------------------------------------------------
Keep on crunching those numbers
-------------------------------------------------------------------------------
More information about the Comp.lang.c
mailing list