is there a equivalent of Java’s labelled break in C# or a workaround

You can just use goto to jump directly to a label.

while (somethingA)
{
    // ...
    while (somethingB)
    {
        if (condition)
        {
            goto label1;
        }
    }
}
label1:
   // ...

In C-like languages, goto often ends up cleaner for breaking nested loops, as opposed to keeping track of boolean variables and repeatedly checking them at the end of each loop.

Leave a Comment