DEV Community

Cover image for Labeled Breakout & GOTO
Jacob Evans
Jacob Evans

Posted on

Labeled Breakout & GOTO

So I saw a post on Twitter, talking about labeled breaks... Which led to people fervently recommending not to do such patterns. Somehow this brought up GOTO, now this is the thing, I have never used GOTO, I Googled it. What I read was likely the correlation to the heavy abuse of GOTO in multi-loop breaks since the example was nested for loops using labeled breaks.

From what I can tell, which is limited. The GOTO was essentially abstracted away by such things as for, while, switch, do, and the like. Reintroducing the GOTO paradigm seems redundant in structured programming.

My naive thought about this is in a modern high-level language there is probably a builtin model that is optimized that does something similar. However, I brought it up here because I want to learn more about it and GOTO beyond some old code and Wikipedia.

Top comments (1)

wrldwzrd89 profile image
Eric Ahnell

Getting out of a series of nested loops is sometimes necessary - I prefer putting the loop in question into its own function and returning early in the event of an exit before the loop series completes, which avoids the need for labeled breaks and the GOTO statement entirely.