Xref: utzoo comp.lang.modula2:1230 comp.lang.c:15873 Path: 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: <739@jupiter.iis.UUCP> <1611@csuna.UUCP> Organization: The Portal System (TM) Lines: 43 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