Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!usc!ucsd!ucbvax!hplabs!hpda!hpwala!hpavla!gary From: gary@hpavla.AVO.HP.COM (Gary Jackoway) Newsgroups: comp.lang.c Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple) Message-ID: <9130010@hpavla.AVO.HP.COM> Date: 23 Mar 90 13:53:54 GMT References: <16188@haddock.ima.isc.com> Organization: Hewlett-Packard Avondale Division Lines: 35 Emuleomo O.O. writes: > I think this [repeat..until] 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 I agree with your point, that using the keyword for two purposes can lead to problems, but your example... > 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) ; > Guess what happens to the above code inadvertently?? You can't make this mistake, because a do statement only captures a single line: do while (condition). The way I differentiate "while (condition) do" from "do while" is by ALWAYS putting {} around the do statement(s). Thus my structure is do { statements } while (condition); By putting the while on the same line as the curly I also improve readability. You never stop to wonder whether this is the start of a "while..do". Gary Jackoway