"for" loops (was Re: C++ vs. Modula2)

Doug Schmidt schmidt at blanche.ics.uci.edu
Mon Jan 30 04:30:36 AEST 1989


In article <1626 at csuna.UUCP> abcscagz at csuna.csun.edu (Jeff Boeing) writes:
++Hoo boy, did I ever mess up in my last posting.
++I forgot that a C "for" loop may be executed zero times.
++So, let me rephrase my conviction that a C "for" loop is superfluous
++because it can be replaced by an equivalent "while" loop, NOT an
++equivalent "do ... while" loop:

I don't think you've gone far enough.  After all, can't both a while
loop and a for loop be replaced by an if statement and a goto?

++
++    for (i = 0; i <= 17; i = sqr(i) + 2)
++       <stuff>;
++

versus

   i = 0;        
LOOP_HEAD:
   if (i <= 17) {
      <stuff>
      i = sqr(i) + 2;
      goto LOOP_HEAD;
   }
   
In fact, aren't all high-level control constructs superfluous?

Doug

p.s.  ;-) ......
--
schmidt at ics.uci.edu (ARPA) |   Per me si va nella citta' dolente.
office: (714) 856-4043     |   Per me si va nell'eterno dolore.
                           |   Per me si va tra la perduta gente.
                           |   Lasciate ogni speranza o voi ch'entrate.



More information about the Comp.lang.c mailing list