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



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").


--
Richard Heathfield
"Usenet is a strange place" - dmr 29 July 1999
http://www.cpax.org.uk
Email rjh at the above domain

.



Relevant Pages

  • Re: while (1) vs. for ( ;; )
    ... Michael B Allen wrote: ... > Should there be any preference between the following logically equivalent ... Prev by Date: ...
    (comp.lang.c)
  • 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 ... Prev by Date: ...
    (comp.lang.c)
  • Re: while (1) vs. for ( ;; )
    ... Ben Pfaff writes: ... >>>Should there be any preference between the following logically equivalent ... Why not move on to something whose intention is clear: ...
    (comp.lang.c)
  • Re: while (1) vs. for ( ;; )
    ... Chris McDonald writes: ... >>Should there be any preference between the following logically equivalent ... Why not move on to something whose intention is clear: ...
    (comp.lang.c)
  • Re: Code formatting question: conditional expression
    ... If you insist on using the conditional expression, my preference would be: ... excessblk = (Block(total - P.BASE, srccol, ...
    (comp.lang.python)

Loading