4 ms·
GOTO is still a legit way to cleanly break out of nested loops. I cringe whenever I hear normie programmers lament on how blanketly bad it is.
by BrissyCoder 8y ago
GOTO is still a legit way to cleanly break out of nested loops. I cringe whenever I hear normie programmers lament on how blanketly bad it is.
- jcranmer 8y agoI prefer the syntax of newer languages that instead have you label the loop and then break/continue the loop of that level. It tends to make it a little clearer that you're doing a multi-level exit.
- cr0sh 8y ago> break out of nested loops -deeply- nested loops at that. I once was on a thread in a forum discussing state machines, and somewhere in the convo the use of GOTO popped up. I wasn't for it, but somebody made mention of how it could be used to implement a state machine very compactly. Then he showed his code - it was done in PBASIC. I saved a copy of that code, because it was very, very elegant. While I knew there were certain very niche cases for GOTO, I never thought that a state machine would qualify. For me, it does now. I don't have the code handy, but it reminded me of Duff's device, if you know what that is - just done in BASIC - and not as a SWITCH-CASE of course...