🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1276

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

#1276
From: diamond
Date: Wed, 30 May 1990 01:52
52 lines
2799 bytes
Followups to comp.lang.c, where most of this belongs.

In article <3093@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:

>I loathe and detest while (1) because it's obfuscatory.
>The thing is, a skilled programmer uses a while (..) statement because
>that's the way it fell out of his preconditions, postconditions,
>invariant, and so on.  You use 'while' to express "here after this
>keyword is all the information you need about when the loop stops."

Exactly the same reasoning applies to the second expression in a
"for" statement.  You use "for" to express "the second expression
after this keyword is all the information you need about when the
loop stops."
(My opinion and argument here are serious, not intended to be satirical.)

>The character sequence (;;) has, I believe, no other use in C.  It's a
>very clear signal "no, it _wasn't_ a mistake, I really _did_ mean to
>put the real loop control somewhere else."

while(1) is an equally clear signal.

>In fact, I would welcome a "lint" option that reported 'break' or
>'continue' statements having a while (..) or do while (..) statement
>as scope as being likely errors.

I loathe and detest all "break" and "continue" statements.  The
language should have been designed differently.  Nonetheless,
"break" and "continue" are suitable for while(1) and for(;;) loops.
Reading becomes difficult when "break" or "continue" occurs in either
a "while" or "for" loop with non-constant terminating condition.

>Um, I've recently had a lot more contact with people from a Pascal
>background than I really wanted.  Quickly now, what's wrong with this:
>	program main;
>	    var i: integer;
>	    procedure p(n: integer);
>		begin
>		    for i := 1 to n do write(' ');
>		    writeln(i);
>		end;
>	    begin
>		p(10);
>	    end.
>(I count three violations of the Pascal Standard.)

Then read the Pascal Standard and count again.  There is one violation.
(Did you think that Pascal lacks a null statement?)

-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.
Technical Details
Message-ID: <1751@tkou02.enet.dec.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamond
References: <5876@buengc.BU.EDU> <12955@smoke.BRL.MIL> <5879@buengc.BU.EDU> <5897@buengc.BU.EDU> <3093@goanna.cs.rmit.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!apple!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamond
From: diamond@tkou02.enet.dec.com (diamond@tkovoa)
Newsgroups: comp.std.c,comp.lang.c
Subject: Re: for(;;) vs. while(1) is a draw
Message-ID: <1751@tkou02.enet.dec.com>
Date: 30 May 90 01:52:18 GMT
References: <5876@buengc.BU.EDU> <12955@smoke.BRL.MIL> <5879@buengc.BU.EDU> <5897@buengc.BU.EDU> <3093@goanna.cs.rmit.oz.au>
Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa)
Followup-To: comp.lang.c
Organization: Digital Equipment Corporation Japan , Tokyo
Lines: 52