break while; break for; break foreach
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri May 14 02:59:38 UTC 2021
On 5/13/21 12:55 PM, Steven Schveighoffer wrote:
> I've had a few occasions where I have to label a loop that contains a
> switch statement (or vice versa), and then write `break label;` in order
> to break out of the outer construct.
>
> Wouldn't it be nice to just have this implicit, and allow `break
> keyword;` where keyword is one of `for`, `while`, `foreach` and even
> `switch`?
>
> The labeling thing has drawbacks as well -- you can only have one label
> of a given name in a function, making it hard when you have compile-time
> loops that generate the same code with the same label (I've had to deal
> with this by enclosing each branch in it's own immediately-called lambda).
>
> Does this make sense as a language feature? I believe it doesn't break
> (no pun intended) any code since you currently can't have a keyword in
> that position.
>
> Could also allow `continue keyword` though that can be dicey, since
> continue doesn't work for `switch`, and you would have to have 2
> different loops to make it reasonable. But for consistency, you could
> have it.
>
> -Steve
break static foreach would be really really nice
More information about the Digitalmars-d
mailing list