Loop "Equivalencies"

Joseph S. D. Yao jsdy at hadron.UUCP
Thu Nov 21 06:02:21 AEST 1985


In article <10200026 at ada-uts.UUCP> richw at ada-uts.UUCP writes:
>I'd like to point out what I think is a bug in Kernighan & Ritchie.
>    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?

I don't have my K&R with me.  I believe that when it got to
describing 'continue' ( a f t e r  describing these loops),
it pointed out that to express 'continue' in the above re-
phrasing, you had to replace it with 'goto contin' and add
the label 'contin:' before expr3.

Obviously, > 1 loop / function means different labels ...
too bad cpp didn't rip off a macro assembler for a label
generator.		;-)

Disclaimer:  No, I use goto's about once a year at most.
But, read Knuth's "Structured Programming Using Goto's":
it  i s  possible!
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list