Ask HN: Do you use goto, or labeled break/continue?
C# 15 (in preview with .NET 11) lets break and continue target an outer loop by label:
outer: for (int x = 0; x < xMax; x++)
{
for (int y = 0; y < yMax; y++)
{
if (ShouldSkipRest(x, y))
continue outer;
if (ShouldExitAll(x, y))
break outer;
}
}
Honestly, "goto" never even comes to mind when I write an algorithm. I find it hard to follow, so when I need to leave nested loops I extract a method and "return" instead.
Do you use "goto" in real code? Do you think you'll use labeled break/continue?
outer: for (int x = 0; x < xMax; x++) {
}Honestly, "goto" never even comes to mind when I write an algorithm. I find it hard to follow, so when I need to leave nested loops I extract a method and "return" instead.
Do you use "goto" in real code? Do you think you'll use labeled break/continue?
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-15#labeled-break-and-continue