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?
https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-15#labeled-break-and-continue
PaulHoule•44m ago
There are legit uses for goto in certain kinds of technical programming like interpreters but there are other ways to do it, similarly that example above is legit but if you are properly dividing your code up into subroutines you don't run into a lot of places where you'd want goto or labeled break/continue, especially in applications programming where you're not going to write sorts or numerical algorithms... Like I'd be likely to reach for it doing the kind of work that I'd be looking in an algorithms book.
hugoj0s3•17m ago