On 2014-06-13 20:03, H. S. Teoh via Digitalmars-d wrote:
On Fri, Jun 13, 2014 at 10:46:17AM -0700, Jonathan M Davis via Digitalmars-d 
wrote:
[...]
for(;;) is a special case with no real benefit IMHO. It's a loop whose
condition is implicitly true rather than actually having a condition
in it.  IMHO, it should required to be at least for(;1;) or
for(;true;), since those don't require a special case.

I disagree, it's not a special case. It's simply a logical consequence
of each part of the for-loop being optional. Prohibiting for(;;) would
*be* a special case, because then you're saying that each component of
the for-loop is optional, *except* when all of them are omitted.

(Not to mention, for(;1;) is truly an eyesore, far worse than for(;;).)


And if that's what you're doing, you might as well just use while(1),
since there's no point in using for over while if you're not doing
anything in the other two parts of the for loop.

Again I disagree. Using for(;;) is completely natural, because the
definition of for() says that each of the 3 parts are optional. Since an
infinite loop loops *unconditionally*, it doesn't have any loop
conditions, so the most natural thing to do is to use a construct where
the loop condition can be omitted -- i.e., for(;;).

On the contrary, using while() here is unnatural because while() expects
a loop condition, but since an infinite loop doesn't have one, you have
to artificially invent a constant value to stick into the loop condition
in order to satisfy the syntax of the while-loop. I find this to be
quite unnatural.

I don't agree. How many other statements allow their parts to be optional. "while" does not, "if" does not.

--
/Jacob Carlborg

Reply via email to