Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!asuvax!noao!amethyst!raw From: raw@math.arizona.edu Newsgroups: comp.lang.c Subject: loops in c Keywords: loop,while,repeat,until.for Message-ID: <1546@amethyst.math.arizona.edu> Date: 29 Mar 90 12:39:13 GMT Sender: news@amethyst.math.arizona.edu Reply-To: raw@math.arizona.edu () Distribution: usa Organization: Dept. of Math., Univ. of Arizona, Tucson AZ 85721 Lines: 47 In article <4543@daffy.cs.wisc.edu> you write: >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: > >for(;;) { > > if (expr) > break; > >} > >or have I missed something here? > >Rick (schaut@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 -------------------------------------------------------------------------------