for(;;) vs. while(1) is a draw

Mark Brader msb at sq.sq.com
Sat May 26 04:59:50 AEST 1990


> > 1 certainly is "logical" ...
> "true" is logical.  "1" has to be explained as a special quirk of C.

Either "while(1)" or "while(TRUE)" requires, if not explanation, at least
a moment's thought on first encounter, because the reader has to think
about which way the degenerate test goes.  What better way to express the
absence of a test than by omitting the test from the statement?

(That C allows "for(;;)" and not also "while()" is presumably a historical
accident.  "while()" looks like a function call, but so does "while(x)".)

But if you think "while(1)" is more readable, well, you write it that way.
Just like brace styles, it's not worth fussing about.

-- 
Mark Brader			"It's simply a matter of style, and while there
SoftQuad Inc., Toronto		 are many wrong styles, there really isn't any
utzoo!sq!msb, msb at sq.com	 one right style."	-- Ray Butterworth

This article is in the public domain.



More information about the Comp.std.c mailing list