Re: while (1) vs. for ( ;; )



Tim Rentsch <txr@xxxxxxxxxxxxxxxxxxx> writes:
> pete <pfiland@xxxxxxxxxxxxxx> writes:
>
>> Tim Rentsch wrote:
>>
>> > I was surprised at how many people reported that a compiler
>> > they use issues a warning for 'while(1)' and gave that as a
>> > reason for giving preference to the 'for(;;)' form. It
>> > seems like a choice should be made on the basis of what's a
>> > better expression (lower defect rate, higher productivity,
>> > better understood by the readers), not on the basis of some
>> > errant warning message.
>>
>> The warning is the tie breaker.
>>
>> There is no difference in defect rate,
>
> Is this statement just one of belief, or are you offering
> some evidence?

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?

>> productivity,
>
> There is for some developers. Among other things, some
> debugging techniques work better when the 'while(1)' form is
> used. If the people who prefer the 'for(;;)' form don't see
> any difference in productivity, that seems to be an argument
> in favor of using the 'while(1)' form.

What debugging techniques are you referring to? Off the top of my
head, I'd say that any debugging technique that treats the two forms
significantly differently is broken, but I'm prepared to be
enlightened.

>> or understanding by the readers.
>
> At least one poster in this thread said something along
> the lines of using 'while' for "looping" and 'for' for
> "iteration". In the non-infinite case, that's usually
> my leaning also. So there is *some* difference in how
> the two forms are understood.

I read both "while (1)" and "for (;;)" as "this is an infinite loop,
or at least one for which the termination condition is not specified",
and any C programmer should be familiar with both forms. I see the
point of preferring "for (;;)" when iterating over some set of
discrete entities, but I don't think it's a strong argument.

In another thread, I've railed against "if (0 = a)", even though it's
semantically identical to "if (a == 0)". And yes, I'm taking the
opposite side of this argument. The difference, which is largely in
my head, is that I don't find either "while (1)" or "for (;;)" to be
ugly or jarring.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: while (1) vs. for ( ;; )
    ... > better expression (lower defect rate, higher productivity, ... > errant warning message. ... There is no difference in defect rate, ... or understanding by the readers. ...
    (comp.lang.c)
  • File - Success Warning Message
    ... I'm getting this weird warning message when I include a file. ... $_html is empty, even though the remote page exist and is working ... Providing Solutions That Increase Productivity ...
    (php.general)