C Style

Mike Wexler mike at peregrine.UUCP
Thu Sep 19 03:28:33 AEST 1985


> 
> The question:
> 	Which of the following code segments is more understandable,
> ...
> versus NO GOTO VERSION
> 
> 	for ( ; (((ch=getch()) < '1' || ch > '5') && ch != 'E') ; )
> 		putchar(BELL);
> 	addch(ch);
> 	refresh();
> 
How about this version
/* input characters until either "E" or a number between 1 and 5 is input */
	for (;;) {
		ch=getch();
		if ((ch>='1'&&ch<='5')||ch=='E') break;
		putchar(BELL);
	}
	addch(ch);
	refresh();

	Some people go to great lengths to get efficiency.  In doing
this they sometimes make there code more difficult to read.
	If a piece of code is difficult to read, then simplify it. There
are many ways of doing this other than putting in goto's.  Goto's should
be avoided accept when they simplify code THAT CAN't BE SIMPLIFIED some
other way.
Mike(always a dreamer) Wexler
15530 Rockfield, Building C
Irvine, Ca 92718
(714)855-3923
(trwrb|scgvaxd)!felix!peregrine!mike

-- 
Mike(always a dreamer) Wexler
15530 Rockfield, Building C
Irvine, Ca 92718
(714)855-3923
(trwrb|scgvaxd)!felix!peregrine!mike



More information about the Comp.lang.c mailing list