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



On Mon, 29 Aug 2005 08:42:47 +0000 (UTC), Richard Heathfield
<invalid@xxxxxxxxxxxxxxx> wrote:

>Michael B Allen said:
>
>> Should there be any preference between the following logically equivalent
>> statements?
>>
>> while (1) {
>>
>> vs.
>>
>> for ( ;; ) {
>>
>> I suspect the answer is "no" but I'd like to know what the consensus is
>> so that it doesn't blink through my mind anymore when I type it.
>
>while(1) will be flagged by many compilers as "conditional expression is
>constant" or some such wording, whereas for(;;) will not be. Consequently,
>for(;;) is preferable out of these two choices.
>
>Personally, I prefer neither choice! I would rather have the loop control
>statement explicitly document the exit condition (unless there genuinely
>isn't one, such as might be the case in an electronic appliance like a
>microwave oven, where "forever" can roughly be translated as "whilst power
>is being supplied to the appliance").

It often happens that there are multiple exit conditions. Is it your
preference to set a "get out" flag for these situations? That's my
preference, though I don't feel strongly about it (and I'm likely to
use multiple function returns, too, when a single return is too
contrived.)
--
Al Balmer
Balmer Consulting
removebalmerconsultingthis@xxxxxxx
.



Relevant Pages

  • Re: while (1) vs. for ( ;; )
    ... >>statement explicitly document the exit condition (unless there genuinely ... > It often happens that there are multiple exit conditions. ... > preference, though I don't feel strongly about it (and I'm likely to ...
    (comp.lang.c)
  • Re: while (1) vs. for ( ;; )
    ... >Should there be any preference between the following logically equivalent ... >I suspect the answer is "no" but I'd like to know what the consensus is ... Balmer Consulting ...
    (comp.lang.c)

Quantcast