are for loops and while loops the same thing?

Chris Torek chris at umcp-cs.UUCP
Sun Apr 6 16:30:07 AEST 1986


In article <139 at mit-amt.MIT.EDU> judith at mit-amt.MIT.EDU (Judith Donath)

[asks yet another `frequently asked' question; perhaps this should be
included in the net.announce.newusers section.]

>K & R, page 56:
>	"The for statement
>		for (expr1; expr2; expr3)
>			statement
>	is equivalent to
>		expr 1;
>		while (expr2) {
>			statement
>			expr3;
>		}"
>		
>Not always true.

Correct.

>K & R, page 62
>	"The continue statement... causes the next iteration of the 
>	enclosing loop (for, while, do) to begin. ..."

Note that this is in the `tutorial' part of the book, and that page
62 comes after page 56.

>Is there any reason or use for this difference in behaviour between 
>while and for?

This is the way most people believe they should behave.

>Are there any implementations in which a continue in a for loop
>passes control to the test [...] ?  

If so, those implementations are incorrect.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list