loops in general

Colin Plumb ccplumb at lion.waterloo.edu
Wed Apr 11 00:52:24 AEST 1990


Actually, C already has a loop syntax that could be extended to
exit-in-the-middle loops.  It would be fun to hack this into GCC.  I
presume the standard would require its usual one diagnostic about the
use of extensions and then be silent on the issue.

Anyway, C currently has

while (expr) stmt
and
do stmt while (expr);

However, ';' is a legal statement, so how about treating these as
special cases of

[do stmt] while (expr) stmt

So I could write a loop like

do 
	c = getchar();
while (c != EOF || !feof(stdin)) {
	<rest of loop>
}

Perl's continue blocks are also nifty, but I don't know of a really
elegant way to add them, and goto cont; ... ; continue: ...; works
just as well.
-- 
	-Colin



More information about the Comp.lang.c mailing list