Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.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: 22 Mar 90 21:29:15 GMT References: <16188@haddock.ima.isc.com> <9130009@hpavla.AVO.HP.COM> Organization: Rensselaer Polytechnic Institute, Troy NY Lines: 54 emuleomo@paul.rutgers.edu (Emuleomo) writes: >In article , peter@ficc.uu.net (Peter da Silva) writes: >What wrong with C having >repeat until > I think this is preferable to > do while > Why? Because using the keyword while for two different loop structures > in a program tends to introduce subtle error that will be hard to find > into the program. Whereas, if the keyword until was used, there will > be no room for such errors. > Consider the following program fragment >etc.... >lots of code >etc.. >do > etc.... > while (some_func(j++)) ; /* This stmt was introduced by a maintenance */ > /* programmer */ > a += b; >while (not_end_of_loop) ; >etc.... >Guess what happens to the above code inadvertently?? That's why I always do the follow, even though it's not necessary: do { ... } while (some condition); Again, good coding style can avoid many potential trouble spots. As for whether do..while is better then repeat..until, I think it's purely a religious issue. I personally don't care, as long as I can have my loops test either at the beginning or at the end. 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. -- Trip Martin night@pawl.rpi.edu