Re: while (1) vs. for ( ;; )
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Mon, 29 Aug 2005 08:42:47 +0000 (UTC)
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
.
- Follow-Ups:
- Re: while (1) vs. for ( ;; )
- From: Tim Rentsch
- Re: while (1) vs. for ( ;; )
- From: Alan Balmer
- Re: while (1) vs. for ( ;; )
- References:
- while (1) vs. for ( ;; )
- From: Michael B Allen
- while (1) vs. for ( ;; )
- Prev by Date: Re: Parity check of a word
- Next by Date: Re: while (1) vs. for ( ;; )
- Previous by thread: Re: while (1) vs. for ( ;; )
- Next by thread: Re: while (1) vs. for ( ;; )
- Index(es):
Relevant Pages
|
Loading