Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!yale!cmcl2!phri!sci.ccny.cuny.edu!rpi!night From: night@pawl.rpi.edu (Trip Martin) Newsgroups: comp.lang.c Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple) Message-ID: Date: 29 Mar 90 22:48:02 GMT References: <4543@daffy.cs.wisc.edu> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 48 schaut@cat9.cs.wisc.edu (Rick Schaut) writes: >In article night@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(;;) { > > if (expr) > break; > >} >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@pawl.rpi.edu -- Trip Martin night@pawl.rpi.edu