Re: while (1) vs. for ( ;; )
- From: "Baxter" <lbax02.spamguard@xxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 18:11:38 -0700
"Charlie Gordon" <news@xxxxxxxxxxx> wrote in message
news:df2rq7$h3e$1@xxxxxxxxxxxxxxxxxxxxxx
> "Keith Thompson" <kst-u@xxxxxxx> wrote in message
> news:lnu0h7qh5r.fsf@xxxxxxxxxxxxxxxxxx
> > Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> writes:
> > > pete <pfiland@xxxxxxxxxxxxxx> writes:
> >
> > I won't try to speak for pete, but since "while (1)" and "for (;;)"
> > are semantically identical, I'd be very surprised if there were any
> > difference in defect rate. It's something that seems so obvious to me
> > that I wouldn't bother trying to measure it without a very good
> > reason. If there were a difference, I'd tend to assume that it's a
> > difference in training (perhaps the books or classes that use one form
> > happen, by coincidence to be better than the ones that use the other
> > form). Do you have some reason to think there's a significant
> > difference?
>
> Assume the programmer always uses while(1) { ... } for his endless loops.
> You quickly get used to interpreting these automatically as you read them,
> without paying much attention.
> What if there are some while(l) { ... } loops as well. Will you always
keep a
> sharp enough eye to catch these correctly ?
>
> I prefer for(;;). That way anything that looks like while(l) will catch
my eye,
> and I will no doubt complain about such a poor choice for a variable name.
>
> Therefore, I agree while(1) is more prone to indirectly causing defect
than
> for(;;).
>
Why not code it like you would read it in English:
bool done = false;
while (!done) { // while not done do
...
bool mainloop = true;
while (mainloop) { // while mainloop do
...
You can further document it like this:
while (!done) { // will never be done while computer is running
...
There's many variations on this:
#define NOTDONE 1
...
while (NOTDONE) {
...
Convey your intent in English (assuming English is your first language)
--
---------------------------------------------------------------------
DataGet & PocketLog www.dataget.com
Data Collectors www.baxcode.com
--------------------------------------------------------------------
.
- Follow-Ups:
- Re: while (1) vs. for ( ;; )
- From: Charlie Gordon
- Re: while (1) vs. for ( ;; )
- From: Keith Thompson
- Re: while (1) vs. for ( ;; )
- From: Chris McDonald
- Re: while (1) vs. for ( ;; )
- References:
- while (1) vs. for ( ;; )
- From: Michael B Allen
- Re: while (1) vs. for ( ;; )
- From: Tim Rentsch
- Re: while (1) vs. for ( ;; )
- From: pete
- Re: while (1) vs. for ( ;; )
- From: Tim Rentsch
- Re: while (1) vs. for ( ;; )
- From: Keith Thompson
- Re: while (1) vs. for ( ;; )
- From: Charlie Gordon
- while (1) vs. for ( ;; )
- Prev by Date: More questions about casting function pointers ..
- Next by Date: Re: More questions about casting function pointers ..
- Previous by thread: Re: while (1) vs. for ( ;; )
- Next by thread: Re: while (1) vs. for ( ;; )
- Index(es):
Relevant Pages
|