3 ms·
> Labeled loops > I'm not yet sure whether this is a good thing or a bad thing. Sure, you can do clever shenanigans now, but something tells me this will make
by magnio 5y ago
> Labeled loops
> I'm not yet sure whether this is a good thing or a bad thing. Sure, you can do clever shenanigans now, but something tells me this will make the code's control flow much harder to follow.
The most popular example I can think of is JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label#using_a_labeled_continue_with_for_loops https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Tbh, I think the opposite is true: without the ability to break outer loops, I have resorted to shenanigans using an auxiliary variable and then have to check it after the loop completes, obscuring the logic of the program. Of course, it does not have the full power of goto, and in this case I think it is a sensible choice.
- erk__ 5y agoRust also has this: https://doc.rust-lang.org/rust-by-example/flow_control/loop/nested.html https://doc.rust-lang.org/rust-by-example/flow_control/loop/...
- wchar_t 5y agoAuthor here. Fair enough! Since writing that I've done a lot of Zig code, which has labeled loops, and I can say it's definitely made a lot of code clearer than it would be otherwise.
- deleted 5y ago[deleted]
- hoytech 5y agoI agree, labelled loops are fantastic. I don't know for sure, but I believe the JavaScript feature was inspired by Perl, which has had them since at least the v4 releases (1989-1993): https://www.rexswain.com/perl4.html#flow https://www.rexswain.com/perl4.html#flow