Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!brl-tgr!tgr!cottrell@nbs-vms.ARPA From: cottrell@nbs-vms.ARPA (COTTRELL, JAMES) Newsgroups: net.lang.c Subject: C style Message-ID: <1556@brl-tgr.ARPA> Date: Tue, 17-Sep-85 18:37:21 EDT Article-I.D.: brl-tgr.1556 Posted: Tue Sep 17 18:37:21 1985 Date-Received: Thu, 19-Sep-85 04:40:27 EDT Sender: news@brl-tgr.ARPA Lines: 78 /* Doug gwyn's version > There are several other non-GOTO ways to rewrite the first example: > > move( 4, 10 ); /* position cursor */ > refresh(); > > valid = false; > while ( !valid ) > switch ( ch = getch() ) /* validate input char */ > { > case 'E': > case '1': > case '2': > case '3': > case '4': > case '5': > valid = true; > break; > > default: /* not valid */ > putchar( BELL ); > } > > addch( ch ); /* echo valid input char */ > refresh(); > > Although this introduces an additional (Boolean) variable, which is > one of the problems with goto-less programming, the variable has > very clear meaning and may actually help in understanding the code. Axually, you don't need the additional boolean. I'm leaving out the stuff before & after the while because I know we can code sequences. while (1) { switch (ch = getch()) { /* validate input char */ case 'E': case '1': case '2': case '3': case '4': case '5': break; default: /* not valid */ putchar(BELL); continue; } break; } I will concede that this starting to become a rat's nest tho. How about this one: do { switch (ch = getch()) { case 'E': case '1': case '2': case '3': case '4': case '5': break; default:putchar(ch = BELL); } } while (ch == BELL); > > 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? > > Mine, of course. You got the right answer here! Everyone likes their own style best. Oh. And put the braces IN THE RIGHT PLACE!!! Do it K&R style. Any other way is fighting a losing battle. You can't beat us. Join us. jim cottrell@nbs */ ------