is there a reason declarative style if are allowed, but not while ?

Tobias Pankrath tobias+dlang at pankrath.net
Sun Feb 28 10:25:09 UTC 2021


On Friday, 26 February 2021 at 20:32:18 UTC, deadalnix wrote:
> D allows for this type of constructs:
>
> if (auto foo = bar()) { ... }
>
> I was trying to do something similar with a while loop, but DMD 
> seems very upset about it. Is there a reason to disallow the 
> following?
>
> while (auto foo = bar()) { ... }

What's also unfortunate is

do {
   bool cond = <expr>;
} while(cond)

does not work.

> onlineapp.d(5): Error: undefined identifier cond



More information about the Digitalmars-d mailing list