Optional braces

kennytm kennytm at gmail.com
Fri Aug 26 14:15:34 PDT 2011


"Steven Schveighoffer" <schveiguy at yahoo.com> wrote:

> Hm... the only problem I see with simply disallowing if(a) if(b) is this:
> 
> if(a)
>   while(condition)
>     if(b)
>       statement;
> else // oops! this goes with if(b)
>   statement;
> 
> Or would this be disallowed as well?  This could not be combined into a 
> single if statement obviously, so the only the option to fix this is  adding braces.
> 
> I'd hate to see this disallowed, which seems perfectly legitimate:
> 
> if(a)
>    while(condition)
>       if(b)
>         statement;
> 
> -Steve

I've created a patch* for dangling else checking. Your first example will
be banned and the second is allowed. Check the test cases there for more
examples.  

*: https://github.com/D-Programming-Language/dmd/pull/336


More information about the Digitalmars-d mailing list