C Style

Richard L. Klappal rlk at chinet.UUCP
Sun Sep 15 07:54:48 AEST 1985


In article <1217 at ihuxe.UUCP> foss at 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)
-------------------------------------------------------------------------



More information about the Comp.lang.c mailing list