do...while vs. repeat...until (was: Errors aren't that simple)

Emuleomo emuleomo at paul.rutgers.edu
Fri Mar 23 02:04:58 AEST 1990


In article <IEC2SG5xds13 at ficc.uu.net>, peter at ficc.uu.net (Peter da Silva) writes:
> In article <383 at bohra.cpg.oz>, ejp at bohra.cpg.oz (Esmond Pitt) writes:
> > In article <OVB2S3Bxds13 at ficc.uu.net> peter at 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. <peter at ficc.uu.net>.
> /      \  'U`
> \_.--._/
>       v

What wrong with C having 

repeat  <stmt> until <condition>
 I think this is preferable  to 
 do  <stmt> while <condition> 

 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 at yes.rutgers.edu)
-- 
** The ONLY thing we learn from history is that we don't learn from history!



More information about the Comp.lang.c mailing list