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



Ben Pfaff <blp@xxxxxxxxxxxxxxx> writes:

>Chris McDonald <chris@xxxxxxxxxxxxxxx> writes:

>> Michael B Allen <mba2000@xxxxxxxxxx> writes:
>>
>>>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.
>>
>> Preference? Why not move on to something whose intention is clear:
>>
>> while(true) {

>In what way are the former two statements' intentions not clear?
>Both of them obviously loop "forever".


I would suggest that both while(1) and for(;;) are potentially unclear
to a person (undergrad. student) seeing C for the first time
(while assuming they haven't seen Java or C++, either).

OK, I suggest that while(true) is *clearer*.

--
Chris.
.



Relevant Pages

  • Re: while (1) vs. for ( ;; )
    ... > Michael B Allen wrote: ... >> Should there be any preference between the following logically equivalent ... > makes the intention of the programmer clearer. ...
    (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: while (1) vs. for ( ;; )
    ... > Should there be any preference between the following logically equivalent ... whilewill be flagged by many compilers as "conditional expression is ...
    (comp.lang.c)
  • 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)
  • Re: while (1) vs. for ( ;; )
    ... >>>so that it doesn't blink through my mind anymore when I type it. ... >> Preference? ... Why not move on to something whose intention is clear: ...
    (comp.lang.c)