Always use braces (was: Suggested new C loop syntax)

Peter da Silva peter at ficc.uu.net
Sun Dec 25 10:47:54 AEST 1988


In article <11037 at ulysses.homer.nj.att.com>, cjc at ulysses.homer.nj.att.com (Chris Calabrese[mav]) writes:
> 	/*
> 	 * assume students have not learned the ',' operator yet
> 	 */
> 	do	{
> 		inchar = getchar();
> 		} while(inchar != EOF && inchar);
> 	return inchar;

I would recommend in this instance to make the test experession:

	inchar != EOF && inchar != '\0'

Since inchar is obviously not a boolean (it has three distinct possible
values: EOF, 0, and anything else).
-- 
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.
Work: uunet.uu.net!ficc!peter, peter at ficc.uu.net, +1 713 274 5180.   `-_-'
Home: bigtex!texbell!sugar!peter, peter at sugar.uu.net.                 'U`
Opinions may not represent the policies of FICC or the Xenix Support group.



More information about the Comp.lang.c mailing list