`if (a = b)' (was Standard indentation?)

Andrew Koenig ark at alice.UUCP
Thu Dec 15 05:09:01 AEST 1988


In article <861 at quintus.UUCP>, ok at quintus.uucp (Richard A. O'Keefe) writes:
 
> I very much like embedded assignments, but that's a poor argument.
> To exit a loop when you find a sentinel (that's two Es, no As), you can do
> 	/* C version */			-- ADA version
> 	for (;;) {			loop
> 	    ch = getchar();		    get(ch);
> 	    if (ch == EOF) break;	    exit when ch = sentinel;
> 	    process(ch);		    process(ch);
> 	}				end loop
> 
> I use the "while" version as an idiom for reading from a stream,
> but it isn't as general a method as the use of 'break'.

Once upon a time I proposed an extension to the C syntax
that would allow a loop to have its (only) exit in the middle,
rather than at the beginning or end.  In that syntax, the
example above would have looked like this:

	do	ch = getchar();
	while (ch != EOF)
		process(ch);

or, with braces:

	do {
		ch = getchar();
	} while (ch != EOF) {
		process(ch);
	}

You will see that this syntax sort of merges

	do S while (E);

and

	while (E) S

into

	do S while (E) S2

with the first two simply becoming degenerate forms of the third.

I couldn't sell anyone on the idea at the time.  It's way too
late now, of course.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.lang.c mailing list