Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!mailrus!nrl-cmf!ukma!gatech!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: `if (a = b)' (was Standard indentation?) Message-ID: <8536@alice.UUCP> Date: 14 Dec 88 19:09:01 GMT References: <5@rsoft.UUCP> <1071@goofy.megatest.UUCP> <861@quintus.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 49 In article <861@quintus.UUCP>, ok@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@europa.att.com