Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c Subject: Re: `if (a = b)' (was Standard indentation?) Message-ID: <1071@goofy.megatest.UUCP> Date: 13 Dec 88 00:54:07 GMT References: <5@rsoft.UUCP> Organization: Megatest Corporation, San Jose, Ca Lines: 45 There is a construct that is a little awkward using standard (Pascal-like) structured statements: You want to read a value from an external source, exit the loop if the value is a sentinal, or process the value and continue if not a sentinal. { int ch; do { ch = getchar(); if(ch != EOF) process(ch); } while (ch != EOF); } The expression !EOF gets evaluated twice. A compiler that does common subexpression-removal and global flow-analysis would fix things, but not all compilers are that smart. Besides, I'm one of those old fashioned guys who wants the compiler to do what I say. Or rather, I would like to be able to say what I really want the compiler to do. So we could do this: for(;;) { int ch = getchar(); if(ch == EOF) break; process(ch); } This is nice, in as much as it moves the declaration of ch one level deeper. But it has the somewhat unstructured "break". Still, not too bad. I prefer the following: { 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."