do...while vs. repeat...until (was: Errors aren't that simple)

Trip Martin night at pawl.rpi.edu
Fri Mar 30 08:48:02 AEST 1990


schaut at cat9.cs.wisc.edu (Rick Schaut) writes:

>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:

It wasn't a request for that kind of loop construct.  I was just trying
to give a different perspective on the loop discussion.  I'm perfectly 
happy with the C looping constructs.  

>for(;;) {
>   <statements>
>   if (expr)
>      break;
>   <statements>
>}

>or have I missed something here?

I never said you couldn't do the exact same thing in C.  I was talking
about how the constructs are viewed by programmers.  

With both a do..while and a while loop, the assumption is that most code
will only want to jump out of the loop at the beginning or the end of
a loop.  Admittedly, this is a good assumption, but there are times when
it might blind programmers to where the test should really be done.  One
example which comes to mind is reading in and processing data.  The test
for end-of-file should really occur in the middle of the loop, after data
has been read in but before it's been processed.  There's a temptation to
kludge the loop so that the test does occur at the beginning or the end.  

With the cycle statement from Plus, that mistake won't be made since no
assumption is made about where the test should be.  


Trip Martin
night at pawl.rpi.edu
-- 

Trip Martin
night at pawl.rpi.edu



More information about the Comp.lang.c mailing list