Suggested new C loop syntax (was `if (a = b)')

T. William Wells bill at twwells.uucp
Thu Dec 22 11:46:35 AEST 1988


In article <2485 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
: 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:
: > >   do      ch = getchar();
: > >   while (ch != EOF)
: > >           process(ch);
: > > or, with braces:
: > >   do {
: > >           ch = getchar();
: > >   } while (ch != EOF) {
: > >           process(ch);
: > >   }
:
: This is a wonderful and clean extension to 'C' that solves the loop problem
: once and for all!

This is a bad syntax.

Why?

Because of this:

	do
		statement
	while (expr);
		statement

See the difference? Well, in case you didn't, it is the semicolon at
the end of the while expression. This is damned hard to spot and does
not lead to a syntax error.

I'll stick to using a break.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.lang.c mailing list