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

Joseph S. D. Yao jsdy at hadron.COM
Sat May 26 00:23:04 AEST 1990


I just lied to 'rn'.  The following, like >75% of what preceded it,
isn't really worth sending or reading, but I thought I'd have my say.

When I was a beginning programmer, I thought the following was cute, so
I used it all over:
	#define ever	(;;)
	...
		for ever {
			...
		}

For that matter, I also define'd:
	#define until(x)	while (!(x))
	#define unless(x)	if (!(x))
to answer people who said "it doesn't have an "UNTIL" keyword, so what
good is it?"

Also, if our universe of discourse IS ENGLISH, then while(1) makes no
sense, because after the subordinate conjuction "while", one expects a
predicate, not a noun or noun phrase.  IN C, however, we all know that
predicates eventually evaluate to the-equivalent-of 1 or 0 ... but I
still teach people that, if they're going to do this kind of thing,
they should define TRUE and use while (TRUE) instead, it makes more
"intuitive sense", whatever that means (different for each of our
intuitions).

NOW, AS I SAID, ALL THIS MAKES NO DIFFERENCE WHATSOEVER.  It has been
shown that while(1) [or, better, while (TRUE)] and for (;;) [or, worse,
for ever] are logically equivalent by the definitions in both K&R and
X3J11.  The purposes of coding a program are (1) to communicate to the
computer what you intend for it to do, and (2) to communicate to other
people working on the same program (now or later) what you intend for
the computer to do.  [The latter is necessary, otherwise we'd compile
programs and throw the source away.  I HOPE you don't do that!]  BOTH
of these constructs do that.  Which is preferable is largely a cultural
thing.

On the other hand, I still prefer for (;;) ...		;-)

	Joe Yao				jsdy at hadron.COM
	( jsdy%hadron.COM@{uunet.UU.NET,decuac.DEC.COM} )
	arc,arinc,att,avatar,blkcat,cos,decuac,\
	dtix,ecogong,grebyn,inco,insight,kcwc,  \
	lepton,lsw,netex,netxcom,phw5,research,  >!hadron!jsdy
	rlgvax,seismo,sms,smsdpg,sundc,telenet, /
	uunet				       /
(Last I counted ...)



More information about the Comp.std.c mailing list