OT: for (;;) {} vs while (true) {}
Claude via Digitalmars-d
digitalmars-d at puremagic.com
Fri Nov 25 02:33:38 PST 2016
On Thursday, 24 November 2016 at 22:09:22 UTC, Dennis Ritchie
wrote:
> On Thursday, 24 November 2016 at 22:04:00 UTC, LiNbO3 wrote:
>> As you can see [1] the `while (true)` is lowered into `for
>> (;true;)` so it's all about what construct pleases you the
>> most.
>>
>> [1]
>> https://github.com/dlang/dmd/blob/cd451ceae40d04f7371e46df1c955fd914f3085f/src/statementsem.d#L357
>
> OK, thanks.
>
> The next question is:
> What principles guided when choosing between `for (;;) { ... }`
> and `while (true) { ... }` ?
>
> For example, there are two options:
> https://github.com/dlang/phobos/blob/master/std/algorithm/sorting.d
Between "for(;;)", "while(true)" and "do while(true)", I would
use the "while (true) { }" for pure readability and semantic
reasons.
I reckon "for(;;)" form is used for debug reasons (so you can
easily insert conditions to transform an infinite loop into a
finite one).
More information about the Digitalmars-d
mailing list