new do-while syntax (Re: `if (a = b)'...)

John Sahr johns at calvin.EE.CORNELL.EDU
Mon Dec 19 06:37:02 AEST 1988


In article <3049 at arcturus> evil at arcturus.UUCP (Wade Guthrie) writes:
>In article <8536 at alice.UUCP>, ark at alice.UUCP (Andrew Koenig) writes:
[suggesting a do-while syntax with the loop test in the middle]
>> 	do {
>> 		ch = getchar();
>> 	} while (ch != EOF) {
>> 		process(ch);
>> 	}
[deletions]
>                         ..........., but the above constructions
>are EXCEEDINGLY hard to read.  I much perfer the method which already
>exists:
>
>	while ( (c=getchar()) != EOF)
>		process(c);
>Wade Guthrie

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, but is cleaner than jamming a bunch of statements
masquerading as an exit condition inside the test.
I'm not thrilled about the syntax, but it is an interesting idea.  It
adds no keywords, breaks no code, resembles if-else syntax, and would solve
some "artistic style" problems I run into.  Of course, one could use 
goto-labels, breaks, or that interesting switch-case-for loop that showed 
up in this group a while back.
Actually, my main objection with the syntax, I realize, is only the
indent/brace style, which differs from my own.  (I won't tread any further
along that path...:-) )

Happy Holidays,

John

-- 
John Sahr,                          School of Elect. Eng.,  Upson Hall   
                                    Cornell University, Ithaca, NY 14853

ARPA: johns at calvin.ee.cornell.edu; UUCP: {rochester,cmcl2}!cornell!calvin!johns



More information about the Comp.lang.c mailing list