🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4599

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

#4599
From: Devin_E_Ben-Hur
Date: Sat, 28 Jan 1989 20:43
43 lines
1619 bytes
Jeff Boeing writes:
> Actually, C's "for" can be duplicated EXACTLY by C's "do ... while" loops.
> Consider:
> 
>     for (i = 0; i <= 17; ++i)
>     {
>         stuff();
>         more_stuff();
>     }
> 
> versus:
> 
>     i = 0;
>     do {
>         stuff();
>         more_stuff();
>     } while (++i <= 17);
> 
> 
> These two iterations are indistinguishable from one another.  The "for" term
> in C is totally superfluous and is only included because it makes it look
> languages that have a more "for"-ish "for" statement, like Pascal or Modula.

Nope.  This is the actual equivalent code:

	i = 0;
	while (i <= 17) {
		stuff();
		more_stuff();
continue_here:
		++i;
	}

The for loop tests at the first iteration, and a continue statement will
branch to the increment not to the test.

The C for statement is a convenience allowing the programmer to place
all loop control statements in one place instead of spreading them all
over the loop.  I've always thought the limits placed on Pascal & Modula's
for statements were silly, but that's just MHO.

Devin_Ben-Hur@cup.portal.com
...!ucbvax!sun!cup.portal.com!devin_e_ben-hur
Technical Details
Message-ID: <14049@cup.portal.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdahl!uunet!portal!cup.portal.com!Devin_E_Ben-Hur
References: <INFO-M2%89011219330825@UCF1VM> <739@jupiter.iis.UUCP> <1611@csuna.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!amdahl!uunet!portal!cup.portal.com!Devin_E_Ben-Hur
From: Devin_E_Ben-Hur@cup.portal.com
Newsgroups: comp.lang.modula2,comp.lang.c
Subject: Re: "for" loops (was Re: C++ vs. Modula2)
Message-ID: <14049@cup.portal.com>
Date: 28 Jan 89 20:43:57 GMT
References: <INFO-M2%89011219330825@UCF1VM> <739@jupiter.iis.UUCP> <1611@csuna.UUCP>
Organization: The Portal System (TM)
Lines: 43