while(...){ ... }else ...

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 18 20:26:34 PST 2015


On Sunday, 18 January 2015 at 18:16:47 UTC, Marc Schütz wrote:
> Unfortunately, this would break existing code:
>
>     if(some_condition)
>         while(some_other_condition) {
>             // ...
>         }
>     else
>         // ...
>
> Currently, the `else` branch belongs to the `if`; with your 
> proposal, it would belong to the `while`.
>
> An `else` always attaches to the closest construct where it can 
> be accepted; AFAICS, this cannot be changed without making the 
> language grammar context-sensitive (it would require parsing 
> `while` inside an `if` differently from other `while`s).

Compiler have simplification of CFG passes that makes this 
feature irrelevant in practice.


More information about the Digitalmars-d mailing list