Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utcsri.UUCP Path: utzoo!utcsri!greg From: greg@utcsri.UUCP (Gregory Smith) Newsgroups: net.lang.c Subject: Re: are for loops and while loops the same thing? Message-ID: <2497@utcsri.UUCP> Date: Mon, 7-Apr-86 12:36:23 EST Article-I.D.: utcsri.2497 Posted: Mon Apr 7 12:36:23 1986 Date-Received: Mon, 7-Apr-86 12:43:50 EST References: <139@mit-amt.MIT.EDU> Reply-To: greg@utcsri.UUCP (Gregory Smith) Organization: CSRI, University of Toronto Lines: 33 Keywords: for, while, continue Summary: not quite, as you say. In article <139@mit-amt.MIT.EDU> judith@mit-amt.MIT.EDU (Judith Donath) writes: [example deleted. I have substituted this from K&R pg. 203] while(...){ for(...){ ... ... contin:; contin:; } } [ Judith pointed out that 'continue' does the re-initialization step on the for loop ] > >Is there any reason or use for this difference in behaviour between >while and for? Definitely. The re-initialization step is intended to be part of the loop control. 'continue' is intended to mean 'abandon this execution of the loop and go on to the next'. Thus you would want the re-initialization step done, so the loop control will work properly. E.g.: execute loop for i==1 to 10, but not for i == skip: for(i=1; i<=10; ++i ){ if( i==skip) continue; ... } If ++i was not done after continue, an infinite loop would result. >Are there any implementations in which a continue >in a for loop passes control to the test, as if for was really >the equivalent of the above structured while loop? If there are, they are incorrect, and they are in trouble. -- "If you aren't making any mistakes, you aren't doing anything". ---------------------------------------------------------------------- Greg Smith University of Toronto UUCP: ..utzoo!utcsri!greg