Path: utzoo!attcan!uunet!cs.utexas.edu!rutgers!aramis.rutgers.edu!paul.rutgers.edu!emuleomo From: emuleomo@paul.rutgers.edu (Emuleomo) Newsgroups: comp.lang.c Subject: Re: do...while vs. repeat...until (was: Errors aren't that simple) Message-ID: Date: 22 Mar 90 16:04:58 GMT References: <16188@haddock.ima.isc.com> <9130009@hpavla.AVO.HP.COM> Organization: Rutgers Univ., New Brunswick, N.J. Lines: 55 In article , peter@ficc.uu.net (Peter da Silva) writes: > In article <383@bohra.cpg.oz>, ejp@bohra.cpg.oz (Esmond Pitt) writes: > > In article peter@ficc.uu.net (Peter da Silva) writes: > > >The only sense in which repeat...until is more natural than do...while is > > > There is a further significant difference between the Pascal > > repeat..until and the 'C' do..while. In Pascal, 'repeat..until' > > delimits a statement-list, not a single statement as in 'C'. > > Oh, granted. But that's not the issue at hand, is it? Pascal could have > had a do-while with the same gross semantics as repeat-until, and C > could have had a repeat-until with the same gross semantics as do-while. > That's a side effect of C's strict insistence on statement blocks being > explicit, where Pascal allows begin, or both, to be implicit. > > the code to generate two sorts of branches for the do-while. > > #define repeat do > #define until(x) while(!(x)) > -- > _--_|\ `-_-' Peter da Silva. +1 713 274 5180. . > / \ 'U` > \_.--._/ > v 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?? --Emuleomo O.O. (emuleomo@yes.rutgers.edu) -- ** The ONLY thing we learn from history is that we don't learn from history!