little quiz (SPOILER... don't read if you don't want the answer)

merlyn at sequent.UUCP merlyn at sequent.UUCP
Fri Mar 23 04:15:51 AEST 1984


>>>>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]



More information about the Comp.lang.c mailing list