Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.7.0.8 $; site uiucdcsb Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcsb!kenny From: kenny@uiucdcsb.CS.UIUC.EDU Newsgroups: net.lang.c Subject: Re: C style Message-ID: <139200011@uiucdcsb> Date: Wed, 25-Sep-85 10:41:00 EDT Article-I.D.: uiucdcsb.139200011 Posted: Wed Sep 25 10:41:00 1985 Date-Received: Sat, 28-Sep-85 04:54:19 EDT References: <1556@brl-tgr.ARPA> Lines: 43 Nf-ID: #R:brl-tgr.ARPA:-155600:uiucdcsb:139200011:000:1171 Nf-From: uiucdcsb.CS.UIUC.EDU!kenny Sep 25 09:41:00 1985 /* Written 6:53 am Sep 23, 1985 by peter@graffiti.UUCP in uiucdcsb:net.lang.c */ >> >> for ( ; (((ch=getch()) < '1' || ch > '5') && ch != 'E') ; ) >> putchar(BELL); >> addch(ch); >> refresh(); > >Obviously. A 'C' programmer would have written: > > while( ((ch=getch()) < '1' || ch > '5') && ch != 'E') > beep(); > addch(ch); > refresh(); > >It's considered bad form to have a for loop with more than 1 empty feild. >Now that you're using a construct that doesn't exist in FORTRAN or BASIC >do you feel better? /* End of text from uiucdcsb:net.lang.c */ For Heaven's sake, the big problem with this code is that the conditional is quite unreadable in in-line code like this. I'd prefer while (illegal (ch = getch())) beep (); addch (ch); refresh (); ... int illegal (ch) char ch; { return ((ch < 1 || ch > 5) && ch != 'E'); } which at least separates the test from the action. I realize that it also moves the test further away physically in the code, but I think the price is worthwhile. k**2 kenny@uiuc.ARPA ...!pur-ee!uiucdcs!kenny Disclaimer: Opinions expressed herein may not be even MINE, much less my employer's.