Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #2218
| From | "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> |
|---|---|
| Newsgroups | comp.programming |
| References | <d7cd0c38-525c-4796-98e4-4a068d91846c@googlegroups.com> <504FC54B.7D2@mindspring.com> <r86dnXXQftOwVNLNnZ2dnUVZ_rCdnZ2d@earthlink.com> |
| Subject | Re: true loop |
| Date | 2012-09-15 10:56 +0100 |
| Message-ID | <irSdnWf7hZIUzMnNnZ2dnUVZ8iqdnZ2d@bt.com> (permalink) |
Patricia Shanahan wrote:
> for(;;) is horribly indirect. Yes, I know that an empty continuation
> condition means continue forever, but what is wrong with saying what one
> means?
I quite strongly disagree. I have always found the "while (true)" idiom to be
unnecessarily indirect -- it /doesn't/ (IMO) "say what it means". What I'm
trying to say is
loop forever
but what "while (true)" is saying is
loop while a condition (which happens always to be true) holds"
It may help illustrate my unease with the idiom if you consider:
while (!false) {...
or even (and I've heard of this one in production code though I haven't seen it
personally):
while (THE_POPE_IS_A_CATHOLIC) {...
(which obviously depends on the appropriate definition elsewhere, and is bad
for that reason /too/).
I might be happier if the idiom was
while () {...}
but that would depend on a special-case one-off rule for "while". The
corresponding idiom using "for" also depends on a rule, but (unlike the case
for "while") that rule is not /special/ -- it already exists for each of the
sub-clauses of the "for" statement anyway. (In C-family languages).
Going back to the OP("bob")'s original question. One thing that I haven't seen
anyone mention is that there are two ways that an infinite loop is used. One
is where the loop is actually expected to run "forever" -- as in the heart of a
scheduler -- or at least until some external processing somewhere breaks the
loop "invisibly", say by calling exit() -- for instance a message pump loop
might take that form. That obviously can't be considered bad practise, but
isn't all that common either.
But the other way it's used is as the framework for a loop which has no overall
controlling condition, but which is terminated by conditional processing within
the loop. Personally I use that form rather often, since often there isn't a
single clear "master" condition. I can imagine that there may be people (the
ones who object to breaking out of loops and who probably also object to
multiple "return" statements) who would object to the:
while (true) { ... processing with breaks/returns... }
idiom (whether expressed with "while" or "for"). If such people do exist then
they are mistaken (I make this absolute statement with no apologies
whatsoever). So my answer to [what might be] the OP's question is that it
isn't considered bad practice (by anyone who isn't wrong) ;-)
-- chris
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
true loop bob <bob@coolfone.comze.com> - 2012-09-11 10:52 -0700
Re: true loop Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-09-11 11:17 -0700
Re: true loop pete <pfiland@mindspring.com> - 2012-09-11 19:12 -0400
Re: true loop Patricia Shanahan <pats@acm.org> - 2012-09-11 16:28 -0700
Re: true loop pete <pfiland@mindspring.com> - 2012-09-11 22:23 -0400
Re: true loop Geoff <geoff@invalid.invalid> - 2012-09-11 19:33 -0700
Re: true loop Patricia Shanahan <pats@acm.org> - 2012-09-11 19:53 -0700
Re: true loop Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-12 02:23 -0700
Re: true loop "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2012-09-15 10:56 +0100
Re: true loop Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-12 02:21 -0700
Re: true loop pete <pfiland@mindspring.com> - 2012-09-12 18:04 -0400
Re: true loop Ian Collins <ian-news@hotmail.com> - 2012-09-13 10:22 +1200
Re: true loop Geoff <geoff@invalid.invalid> - 2012-09-12 19:06 -0700
Re: true loop Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-09-13 16:27 +0200
Re: true loop Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-09-19 07:04 -0700
Re: true loop Patricia Shanahan <pats@acm.org> - 2012-09-19 07:30 -0700
csiph-web