OT: for (;;) {} vs while (true) {}
Claude via Digitalmars-d
digitalmars-d at puremagic.com
Fri Nov 25 03:53:43 PST 2016
On Friday, 25 November 2016 at 11:10:44 UTC, Timon Gehr wrote:
> On 25.11.2016 11:33, Claude wrote:
>> ...
>>
>> Between "for(;;)", "while(true)" and "do while(true)", I would
>> use the
>> "while (true) { }" for pure readability and semantic reasons.
>> ...
>
> What semantic reasons?
In the general sense:
- While true (is always true), I loop.
Is more meaningful and conceptually easy then the empty for
statement :
- For "empty initialization statement" until "I don't know (so
forever by default)" and "not iterating", I loop.
>> I reckon "for(;;)" form is used for debug reasons (so you can
>> easily
>> insert conditions to transform an infinite loop into a finite
>> one).
>
> You can just as easily edit the while condition. I use it
> because "unconditional loop" is less silly than "loop until
> true is false".
I was just trying to explain why one would use for(;;) instead of
while(true), you've got only one line to edit.
It's in same vein as using:
if (cond)
{
}
More information about the Digitalmars-d
mailing list