"If you want to go somewhere, goto is the best way to get there." -- Ken Thompson
GOTO statement performs a one-way transfer of control to a line of code marked by a
LABEL statement. In lame man terms, the execution jumps to the line where the wanted
LABEL is found and continues from there.
While maligned by Edsger W. Dijkstra and his cohorts,
GOTO is very useful in many situations. Its reputation is undeserved and mostly perpetuated by people that don't understand the origins of the criticism or how the statement can be used.
You also can't make a COBOLesque language without
GOTO, so (due to popular request) here we've added it to the language.
PROCEDURE:GOTO startLABEL startdisplay "> starting..." crlfGOTO endingLABEL middledisplay "> entering the middle section..." crlfsub-procedure cool-codeGOTO cooldisplay "hmm... is this cool?" crlfLABEL cooldisplay "wow, yeah! cool code!" crlfend sub-procedureLABEL endingCALL cool-codedisplay "> that's the end" crlf
In the output of this program you can see the
middle LABEL and the start of the
cool-code SUB-PROCEDURE are skipped:
> starting...wow, yeah! cool code!> that's the end
In order to keep
GOTO from turning your source into "unmaintainable spaghetti code", both your
GOTO statement and the
LABEL it jumps to have to be used together in the same sub-procedure or in the main code body of an LDPL program. So you can't
goto across sub-procedures or into them, or anything like that.