Article View: comp.std.c
Article #1281Re: for(;;) vs. while(1) is a draw
From: Joseph S. D. Yao
Date: Fri, 25 May 1990 14:23
Date: Fri, 25 May 1990 14:23
47 lines
2529 bytes
2529 bytes
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@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 ...)
Technical Details
Message-ID:
<892@hadron.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!haven!decuac!hadron!jsdyReferences:
<5876@buengc.BU.EDU> <12955@smoke.BRL.MIL> <5879@buengc.BU.EDU> <12971@smoke.BRL.MIL> <5897@buengc.BU.EDU> <4193@castle.ed.ac.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!haven!decuac!hadron!jsdy From: jsdy@hadron.COM (Joseph S. D. Yao) Newsgroups: comp.std.c Subject: Re: for(;;) vs. while(1) is a draw Message-ID: <892@hadron.COM> Date: 25 May 90 14:23:04 GMT References: <5876@buengc.BU.EDU> <12955@smoke.BRL.MIL> <5879@buengc.BU.EDU> <12971@smoke.BRL.MIL> <5897@buengc.BU.EDU> <4193@castle.ed.ac.uk> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 47