May 14, 2021
On 5/13/21 4:14 PM, sighoya wrote:
> On Thursday, 13 May 2021 at 19:36:28 UTC, Steven Schveighoffer wrote:
>> The problem I've had with it is that a label cannot be repeated within a function, so it's hard to write generic code which requires this feature.
> 
> Can't this be relaxed in some way?
> 

I'm not sure how. If you were not able to jump into scopes, then it might make sense to allow multiple labels of the same name.

Besides, this doesn't fix the issues that you brought up. If you have multiple labels, named the same thing, how do you decide which one to go to?

-Steve
May 14, 2021
On 5/14/21 10:17 AM, Steven Schveighoffer wrote:
> On 5/13/21 4:14 PM, sighoya wrote:
>> On Thursday, 13 May 2021 at 19:36:28 UTC, Steven Schveighoffer wrote:
>>> The problem I've had with it is that a label cannot be repeated within a function, so it's hard to write generic code which requires this feature.
>>
>> Can't this be relaxed in some way?
>>
> 
> I'm not sure how. If you were not able to jump into scopes, then it might make sense to allow multiple labels of the same name.
> 
> Besides, this doesn't fix the issues that you brought up. If you have multiple labels, named the same thing, how do you decide which one to go to?

Hm... possibly another solution, is to attribute the label as "scope only", that is, it's only valid within the scope it's declared in. This is kind of similar to how case labels work.

Like:

```d
static foreach(...) {
{ // note extra scope needed
   scope loop:
   foreach(...) {
       switch(...) {
           break loop;
       }
   }
}}

// goto loop; // would be an error
```

This actually might be more powerful than just breaking out of a given loop, because it would enable other label statements like `goto`, and also allows dealing with nested loops.

-Steve
May 14, 2021
On 5/13/21 10:59 PM, Andrei Alexandrescu wrote:

> 
> break static foreach would be really really nice

Different problem -- this would add a feature that currently doesn't exist. I think there are good reasons why you can't break on a static foreach (a static break might be reasonable though).

-Steve
1 2
Next ›   Last »