Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: new do-while syntax Message-ID: <1716@buengc.BU.EDU> Date: 18 Dec 88 23:15:02 GMT References: <3049@arcturus> <864@calvin.EE.CORNELL.EDU> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 49 In article <864@calvin.EE.CORNELL.EDU> johns@calvin.ee.cornell.edu.UUCP (John Sahr) writes: >>In article <8536@alice.UUCP>, ark@alice.UUCP (Andrew Koenig) writes: >[suggesting a do-while syntax with the loop test in the middle] > >I think the point of Mr. Koenig's proposal was to handle larger loops than >the literal interpretation of his example indicated. Consider >>> do { >>> ch = getchar(); > ch &= MASK; > ch = table_look_up[ch]; > report_status(ch); >>> } while (ch != EOF) { >>> process(ch); > process2(ch); > process3(ch); >>> } > >This too, is contrived. Pardon my two-cent kibbitz, but what's wrong with using the comma operator to do that for which it is ideally suited? I find the syntax as described above to be confusing. All of the "ch =" statements are in the do-while loop, and all of the "process()" statements are subsequent to the loop, no? No. But it seems so. (Unless of course I've got it exactly backwards; It Can Happen, especially when I'm entering a discussion I just now discovered.) The K&R-conformant version would be: do { process(ch); process2(ch); process3(ch); } while ( ch = getchar(), ch &= MASK, ch = table_look_up[ch], report_status(ch), ch != EOF ); See? No muss, no fuss, sez who only curly-brackets get special indentation, and you get to tell your grandchildren that you once used the comma operator, which I consider one of the prime elegances of the C language. --Blair ",,,,"