If Statement with Declaration

Moritz Maxeiner via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 20 05:53:43 PDT 2017


On Wednesday, 19 July 2017 at 15:31:08 UTC, ag0aep6g wrote:
> On 07/19/2017 03:30 PM, sontung wrote:
>> So I was thinking of some sort of syntax like this:
>> 
>>      if(int i = someFunc(); i >= 0)
>>      {
>>          // use i
>>      }
>> Thoughts on this sort of feature?
>
> I'd prefer a new variant of `with`:
>
> ----
> with (int i = someFunc()) if (i >= 0)
> {
>     // use i
> }
> ----

It'd be nice to have either of these available in D, though I'd 
prefer the `with` one, since
- `with` is currently not widely used - usually only for things 
like `switch (var) with (EnumName) {...}`; this would make `with` 
pull its own weight (so to speak)
- I think it is way easier to read


More information about the Digitalmars-d mailing list