Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site hadron.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: Loop "Equivalencies" Message-ID: <84@hadron.UUCP> Date: Wed, 20-Nov-85 15:02:21 EST Article-I.D.: hadron.84 Posted: Wed Nov 20 15:02:21 1985 Date-Received: Sat, 23-Nov-85 09:52:33 EST References: <10200026@ada-uts.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 32 In article <10200026@ada-uts.UUCP> richw@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@seismo.{CSS.GOV,ARPA,UUCP}