Loop "Equivalencies"

Doug Gwyn <gwyn> gwyn at brl-tgr.ARPA
Tue Nov 19 23:52:26 AEST 1985


> In Appendix A (C Reference Manual), p. 202, and p. 56, it says that
> the following:
> 
>     for (expr1; expr2; expr3)
>         statement
> 
> is equivalent to:
> 
>     expr1;
>     while (expr2) {
>         statement
>         expr3;
>     }
> 
> This is not true if "statement" is a block which contains a "continue"
> since, in the first case, "expr3", is executed after the continue but
> is not in the second case.
> 
> Am I missing something?

No, you have caught K&R in a misleading statement.  The equivalence
is only approximate, and continue breaks the strict equivalence.
Harbison & Steele (p. 209) have this right.



More information about the Comp.lang.c mailing list