budd@arizona.UUCP (03/21/84)
While we are discussing C, how many people believe that
for (initial; test; update) statement;
is ALWAYS equivalent to
initial;
while (test) {
statement;
update;
}
how many people can cite the exception to the above rule? (ie, one
clearcut case where they produce different results).
tgg@hou5e.UUCP (03/22/84)
>While we are discussing C, how many people believe that > for (initial; test; update) statement; >is ALWAYS equivalent to > initial; > while (test) { > statement; > update; > } >how many people can cite the exception to the above rule? (ie, one >clearcut case where they produce different results). Easy - what about: for ( a= 0; a < 100; a++ ) if ( a % 10 == 0 ) printf("where a is a multiple of ten is %d\n",a); else continue; /* bad example but it works */ Tom Gulvin AT&T Information Systems - Holmdel
neal@denelcor.UUCP (Neal Weidenhofer) (03/22/84)
************************************************************************** >While we are discussing C, how many people believe that > > for (initial; test; update) statement; > >is ALWAYS equivalent to > > initial; > while (test) { > statement; > update; > } > >how many people can cite the exception to the above rule? (ie, one >clearcut case where they produce different results). Are you referring to the fact that if "test" is omitted, it is equivalent to ... while(1) ... Otherwise, K&R says it's the same (p. 202) K&R says it I believe it That settles it :-) Seriously, I am wondering if I broke my compiler by making it work that way. Regards, Neal Weidenhofer Denelcor, Inc. <hao|csu-cs|brl-bmd>!denelcor!neal
merlyn@sequent.UUCP (03/22/84)
>>>>While we are discussing C, how many people believe that >>>> >>>> for (initial; test; update) statement; >>>> >>>>is ALWAYS equivalent to >>>> >>>> initial; >>>> while (test) { >>>> statement; >>>> update; >>>> } >>>> >>>>how many people can cite the exception to the above rule? (ie, one >>>>clearcut case where they produce different results). One that comes to mind immediately is the use of "continue" within "statement". For the for loop, continue makes "update" happen, where in the while loop continue doesn't. For example, this statement: for (i=1; i<=10; i++) continue; eventually exits (after 10 iterations), where: i=1; while (i<=10) { continue; i++; } doesn't. Randal L. Schwartz, esq. Sequent Computer Systems, Inc. UUCP: ...!tektronix!ogcvax!sequent!merlyn (official legendary sorcerer of the 1984 Summer Olympics) BELL: (503)626-5700 Original Material (C) 1984 by Randal L. Schwartz [ALL RIGHTS RESERVED]
hamilton@uiucuxc.UUCP (04/03/84)
#R:arizona:-903100:uiucuxc:21000010:000:103 uiucuxc!hamilton Apr 2 01:11:00 1984 trivial answer is "for(;;)", depending on how you want to call "if()" (my compiler says it's illegal).