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: C Style Message-ID: <180@chinet.UUCP> Date: Wed, 11-Sep-85 03:50:02 EDT Article-I.D.: chinet.180 Posted: Wed Sep 11 03:50:02 1985 Date-Received: Fri, 13-Sep-85 04:28:26 EDT Organization: chinet, Public Access UN*X, Chicago, IL Lines: 57 Keywords: which is better? The question: Which of the following code segments is more understandable, (readable, structured, etc) given the current attitudes about the presence of goto's in programming? (For the sake of argument, assume I left the comments out of both versions entirely. I included them here in case people are not clear what the various curses routines do.) GOTO VERSION: . . . noecho(); /* turn off echo */ retry: move(4,10); /* set cursor position */ refresh(); /* update screen */ ch = getch(); /* get input character (without echo) */ if ((ch < '1' || ch > '5') && ch != 'E') { /* valid input is 1 thru 5 or 'E' */ putchar(BELL); /* sound bell on invalid input */ goto retry; } addch(ch); /* echo the valid character */ refresh(); /* update screen */ . . . versus NO GOTO VERSION for ( ; (((ch=getch()) < '1' || ch > '5') && ch != 'E') ; ) putchar(BELL); addch(ch); refresh(); My background is predominately from a FORTRAN-BASIC-PL/I environment, so I tend to think of the FOR (.;.;.){} in terms of DO .. CONTINUE, iterative DO .. END or DO WHILE .. END constructs, where this kind of an assignment in the conditional is verboten. I guess what I'm really asking is: If you had to modify this program, written by someone else who commented it sparsely, which style would you prefer to work on? -- 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) -------------------------------------------------------------------------