If Statement with Declaration

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 4 06:56:57 PDT 2016


On Friday, 4 November 2016 at 13:38:30 UTC, Superstar64 wrote:
> On Thursday, 3 November 2016 at 22:32:17 UTC, Stefan Koch wrote:
>> Just Introduce another block
>> {
>>   int i = someFunc();
>>   if (i >= 0) { ... }
>> }
>> // i is not visible here
>
> That adds 2 indention levels after formatting.
>
> Unfortunately this doesn't work:
> ---
> {
>     int i = someFunc();
>     if (i >= 0):
>     //your code here
> }
> // i is not visible here
> ---

If you don't like indentation you can simply ignore it or you can 
use old goto :)

{
    int i = someFunc();
    if (i < 0) goto outer;
    // your code here
}

outer:
// i is not visibe here






More information about the Digitalmars-d mailing list