OT: for (;;) {} vs while (true) {}

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 24 16:51:14 PST 2016


On 11/24/2016 05:09 PM, 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

I wouldn't ding anyone in a code review for using one vs the other. -- 
Andrei


More information about the Digitalmars-d mailing list