-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Labelled loops as targets for break and continue. #5883
Comments
I often felt the need of a break with label. |
So spelling There's absolutely zero reason to be afraid of using goto statements to break out of loops in C#- they cannot jump between methods and this is their intended use. |
Yes but there's still some stigma associated to them |
There is a slight semantic difference between The equivalent One possible use for this syntax would be to create a rule disallowing the use of |
Yes of course you also have to move the labels. After the loop for break, at its end for continue. It might not be as intuitive as a break or continue. |
It's funny, the negative stigma became attached to That said, I don't think I've ever found a use for bool found = false;
for (int i = 0; !found && i < x; i++) {
for (int j = 0; !found && j < y; j++) {
if (array[i, j].Equals(myNumber)) {
found = true;
}
}
} The one thing I don't really like about Java's implementation is that |
We don't have that as a goal. |
Why this proposal is closed? |
Because the requested change isn't going to happen. |
Loop statements that are prefixed with a label can be the target of
break
andcontinue
statements.break
andcontinue
can accept a single parameter that must be a label of an enclosing loop in the same method and apply to that loop instead of the innermost one.Rationale: getting rid of the most common use of
goto
, restricting it to generated jump tables.Rewritten example from C# reference (
goto
):The text was updated successfully, but these errors were encountered: