You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possibly ambiguous usage of break in C# switch statement #9566
I know this might be a "gotcha", but within the context of a switch statement inside of a loop, to a human, it can be confusing what "break" is referring to.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: e4b4ba4c-b602-9335-97d1-3b8ac23e6cb3
Version Independent ID: c53ac7c0-56f8-06cb-0f06-fdfc389358bd
Is there more information that you need for this than what is available in the 2nd sample? That break breaks out of the inner loop, but not the outer loop.
I was referring to a switch statement inside of a loop, so an example of that would be perfect. Two loops can make it easier to tell what's going on, because you need curly brackets for both (if they're more than one line of code). I don't have access to the code I was looking at when I opened this, but because there can be both breaks (switch and loop) in the same code block -- that syntax can be confusing.
Move the switch example before the nested loop example.
Add text introducing the last (nested loop) example stating that 'break` exits the current branch or loop statement. Reinforce it by stating that this means only one level.
add a final example with a lop and an embedded switch statement.
@BillWagner When adding a new snippet to the dotnet/samples repository, should this issue be referenced in commit message, then a PR submitted to samples, then a PR submitted to dotnet/docs repository for this issue?
Either in the commit message or in the PR description is enough. You can then create the docs PR right after, just call out that is dependent on the samples PR you created and we'll make sure to review after the samples PR is merged.
Activity
BillWagner commentedon Jan 14, 2019
@ryanwebjackson You are correct.
Is there more information that you need for this than what is available in the 2nd sample? That
breakbreaks out of the inner loop, but not the outer loop.ryanwebjackson commentedon Jan 22, 2019
I was referring to a switch statement inside of a loop, so an example of that would be perfect. Two loops can make it easier to tell what's going on, because you need curly brackets for both (if they're more than one line of code). I don't have access to the code I was looking at when I opened this, but because there can be both breaks (switch and loop) in the same code block -- that syntax can be confusing.
BillWagner commentedon Mar 4, 2019
The right fix is to make the following changes:
switchexample before the nested loop example.[-]Possibly ambiguous usage[/-][+]Possibly ambiguous usage of `break` in C# `switch` statement[/+]davidlfox commentedon Oct 8, 2019
@BillWagner When adding a new snippet to the dotnet/samples repository, should this issue be referenced in commit message, then a PR submitted to samples, then a PR submitted to dotnet/docs repository for this issue?
mairaw commentedon Oct 8, 2019
Either in the commit message or in the PR description is enough. You can then create the docs PR right after, just call out that is dependent on the samples PR you created and we'll make sure to review after the samples PR is merged.