Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 from ihnp4 4.3bsd-beta 6/6/85; site chinet.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!chinet!rlk From: rlk@chinet.UUCP (Richard L. Klappal) Newsgroups: net.lang.c Subject: Re: C Style Message-ID: <184@chinet.UUCP> Date: Sat, 14-Sep-85 17:54:48 EDT Article-I.D.: chinet.184 Posted: Sat Sep 14 17:54:48 1985 Date-Received: Sun, 15-Sep-85 12:11:23 EDT References: <180@chinet.UUCP> <1217@ihuxe.UUCP> Reply-To: rlk@chinet.UUCP (Richard L. Klappal) Organization: chi-net, Public Access UN*X, Chicago IL Lines: 73 In article <1217@ihuxe.UUCP> foss@ihuxe.UUCP (foss) writes: >> >> The question: >> Which of the following code segments is more understandable, >> >> GOTO VERSION: >> [deleted example] >> versus NO GOTO VERSION >> [deleted example] >---------------------------- > >Enable Flame Thrower: > >It is a tie. Both versions are lame and don't use >the most appropriate construct avaliable. > -> Goto's are for teen-agers who play video games > (and grow up to play D & D). > -> With the 'for' loop, the general idea is: > > for( initial condition; final condition; change condition ) > foo; > > Unfortunately, the 'for' loop above has no > initial condition and no change condition. >............................. > >I suggest a more appropriate construct, the 'while' loop: > > while(( ch = getch()) != EOF ) > { > if(( ch < '1' || ch > '5') && ch != 'E') > putchar( BELL ); > addch( ch ); > refresh(); > } /* end while */ > >This IS more readable and demonstrates what >really needs to be done by the loop. > >Disable Flame Thrower: > >---------------------------------------------------------------- >Raymond M. Foss -> AT&T Bell Laboratories -> ..!ihnp4!ihuxe!foss >---------------------------------------------------------------- I think you missed the point slightly, but answered the question anyway. Now that I stand back abit and look at your response, I think while (((ch=getch()) < '1' || ch > '5') && ch != 'E') putchar(BELL); would be the construct I wanted. The intent is to read ONE character which MUST be a digit between 1 and 5, inclusive, or an 'E'. EOF would be invalid, plus the fact that this package is intended for non-technical types who wouldn't know CTRL D from their left ear (no insult intended, but it's outside their realm of experience). Thanks. Sometimes I get too close so close to the tree that I see plenty of bark, but no forest. -- Richard Klappal UUCP: ..!ihnp4!chinet!uklpl!rlk | "Money is truthful. If a man MCIMail: rklappal | speaks of his honor, make him Compuserve: 74106,1021 | pay cash." USPS: 1 S 299 Danby Street | Villa Park IL 60181 | Lazarus Long TEL: (312) 620-4988 | (aka R. Heinlein) -------------------------------------------------------------------------