If Statement with Declaration

mogu via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 3 17:04:28 PDT 2016


On Thursday, 3 November 2016 at 22:32:17 UTC, Stefan Koch wrote:
> On Thursday, 3 November 2016 at 22:29:34 UTC, Jerry wrote:
>>
>> So I was thinking of a way of extending if statements that 
>> have declarations. The following being as example of the 
>> current use of if statements with declarations:
>>
>> [...]
>
> Just Introduce another block
> {
>   int i = someFunc();
>   if (i >= 0) { ... }
> }
> // i is not visible here

Introducing a block is not intuitive and cause an identation. As 
a reference, C++17 has adopted a proposal about this, and 
extended to switch:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0305r1.html



More information about the Digitalmars-d mailing list