delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/09/12:45:57

From: Ed Beroset <beroset AT mindspring DOT com>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,rec.games.programmer
Subject: ccoding empty loops
Date: Thu, 09 Oct 1997 10:58:10 -0400
Organization: MindSpring Enterprises
Lines: 43
Message-ID: <343CF102.56A76006@mindspring.com>
References: <60mlov$233 AT mozo DOT cc DOT purdue DOT edu> <875516249 DOT 582482 AT ash DOT mcs DOT net DOT au> <60r0ac$orh AT mozo DOT cc DOT purdue DOT edu> <875704166 DOT 555705 AT ash DOT mcs DOT net DOT au> <01bcce62$2ff12160$2b40cbc2 AT russnt> <60v8m1$o1p AT mozo DOT cc DOT purdue DOT edu> <875834750 DOT 944051 AT ash DOT mcs DOT net DOT au> <611hl8$1ss AT mozo DOT cc DOT purdue DOT edu> <876011581 DOT 336046 AT ash DOT mcs DOT net DOT au> <6176pv$mot AT mozo DOT cc DOT purdue DOT edu> <876206796 DOT 710948 AT ash DOT mcs DOT net DOT au> <61dktf$qe1 AT mozo DOT cc DOT purdue DOT edu> <MPG DOT ea42db081ef676598993f AT news DOT videotron DOT net> <61dqlr$6c8 AT mozo DOT cc DOT purdue DOT edu> <34568437 DOT 5936836 AT news1 DOT newscene DOT com> <61h58r$rhn AT mozo DOT cc DOT purdue DOT edu> <343CDE32 DOT 44A18B95 AT mindspring DOT com> <MPG DOT ea6adfce862871b98994d AT news DOT videotron DOT net>
NNTP-Posting-Host: user-38lc51a.dialup.mindspring.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

sumatose AT NOSPAM DOT usa DOT net wrote:
> 
> In group rec.games.programmer, Ed Beroset says...

> > While that's certainly an improvement over the single semicolon, I use
> > this instead:
> >
> > while (semaphore)
> >       continue;
> >
> > "continue" is, of course a C++ keyword -- the lesser known sibling of
> > "break."  It has the significant advantage that unlike either of the
> > above constructs, even a casual reader can be absolutely certain about
> > the intention of the original programmer.
> 
> That's odd.  I had to think for a minute about what that code was
> meant to do.  

Really?  I'm curious about what part of the construct you found
confusing.  Was the "continue" keyword unfamiliar to you?  It seems
quite completely clear to me.  Perhaps adding a comment (as in the
braces version) would help:

while (semaphore)
	continue;  // do nothing

> In fact, I would have removed if I had found it in
> a program I worked on...  Getting rid of the braces is just
> confusing 

OTOH, I would look at the empty braces and ponder what the programmer
forgot to code.

> - and in fact violates the coding standards of the last
> three places I worked at. 8-)

How very odd.  Do those coding standards state something like, "all
while statements shall have curly braces" or do they have some specific
prohibition against the "continue" keyword?  The former I could
understand (if not actually endorse).  I suppose it might make things
slightly easier for those of us who also code in Perl.  :-)

Ed

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019