`if (a = b)' (was Standard indentation?)
Richard A. O'Keefe
ok at quintus.uucp
Wed Dec 14 12:48:48 AEST 1988
In article <1071 at goofy.megatest.UUCP> djones at megatest.UUCP (Dave Jones) writes:
>{ int ch;
> while( (ch = getchar()) != EOF )
> process(ch);
>}
>
>This says it almost literally, "While I get a ch that is not
>a sentinal, I want to continue processing."
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'.
More information about the Comp.lang.c
mailing list