Translate break and continue with label
Currently one of the biggest headaches I've run into is that break and continue with label aren't translated, and the resulting code is likely incorrect as you would usually only use a label if you wanted to break/continue an outer loop, not the inner-most one. I'm wondering if we could translate break and continue with label to use goto, perhaps. I believe this should work, but let me know your thoughts:
Break-with-label input:
label_1:
while (true) {
while (true) {
break label_1;
}
}
Break-with-label proposed output:
label_1:
while (true) {
while (true) {
goto label_1_break;
}
}
label_1_break: ;
Continue-with-label input:
label_1:
while (true) {
while (true) {
continue label_1;
}
}
Continue-with-label proposed output:
label_1:
while (true) {
while (true) {
goto label_1_continue;
}
label_1_continue: ;
}
I just did a quick test and it seems to work but I'm worried that I'm missing something. The semicolon after the C# labels are needed to make it a valid label target but they're basically a noop for jumping purposes.
Interesting. I wasn't aware of labeled breaks/continues in Java.
I am seeing a number of csharplang proposals which would add some type of support for labeled breaks/continues in C# but none of which have moved passed the proposed stage. Seems to be a controversial topic.
Do you mind sharing how you have translated the labeled breaks/continues to goto?
My translation was by hand, an example of how we could accomplish it.