C# 15 adds labeled break and continue for nested loops
In C# 15, shipping with .NET 11, break and continue can target an outer loop by label: break search; and continue orders;. This removes boolean flags and goto when exiting nested loops; .NET 11 is currently at Release Candidate 1.
- A label is placed on a loop or switch, then named in break/continue
- On the .NET 11 RC1 SDK, #error version reports Language version 15.0 with no LangVersion set
- On the .NET 10 SDK (C# 14) the same code fails with CS8652: feature is in Preview
- Style rule IDE0410 flags bool-flag and goto patterns and suggests labeled jumps
Read next
Policy