for <==> while (an exception)

Stephen J. Muir stephen at dcl-cs.UUCP
Mon Jul 15 09:17:28 AEST 1985


In article <200 at ur-cvsvax.UUCP> bill at ur-cvsvax.UUCP (Bill Vaughn) writes:
>Section 3.5 of K&R (p. 56) states that the 'for' loop and 'while' loop
>can be made equivalent i.e.
>
>					expr1;
>for (expr1; expr2; expr3)		while (expr2) {
>	statement		<==>		statement
>						expr3;
>					}
>
>Are there any other exceptions?

Here's another ...
An infinite "for" loop is given by "for (;;) statement".  The equivalent
"while" expression is, logically, "while () statement".  As this fails to
compile, one has to resort to "while (1) statement"; which is less efficient
in most cases as code is generated to test if "1" equals "0".
-- 
UUCP:	...!seismo!mcvax!ukc!dcl-cs!stephen
DARPA:	stephen%lancs.comp at ucl-cs	| Post: University of Lancaster,
JANET:	stephen at uk.ac.lancs.comp	|	Department of Computing,
Phone:	+44 524 65201 Ext. 4599		|	Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution	|	LA1 4YR



More information about the Comp.lang.c mailing list