nested loops interruption with break X, continue X #5521
-
|
Proposal The problem of interrupting nested loops, I believe, has been discussed many times. The solution I want to propose is based on specifying the number of interrupted loops after the word "break", as in some other languages. With the difference that the nesting level is specified in Roman numerals. Example foreach (var text in texts)
{
foreach (var sentence in text.Split('.'))
{
foreach (var word in sentence.Split(' '))
{
if (word == "hello")
{
//some logic
break II;
}
else if (word == "world")
{
//some logic
break all;
}
}
}
}in this example |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
See #1597 |
Beta Was this translation helpful? Give feedback.
-
|
I would not be opposed to the idea of targeted breaks. However, I can say with confidence that the ldm would never approve using roman numerals here. That's a complete non starter. |
Beta Was this translation helpful? Give feedback.
-
|
I actually prefer this idea better than labeled breaks/continues (which I consider only as an unnecessary workaround for gotophobia). But it definitely should use normal integer literals instead of roman numbers. |
Beta Was this translation helpful? Give feedback.
-
|
Proposal started here: https://github.com/dotnet/csharplang/blob/main/proposals/labeled-break-continue.md Closing this out to move discussion there. |
Beta Was this translation helpful? Give feedback.
I actually prefer this idea better than labeled breaks/continues (which I consider only as an unnecessary workaround for gotophobia). But it definitely should use normal integer literals instead of roman numbers.