On this page:
Label Lines, The GOTO Command, Using GOTO, GOTO Loops.
Label lines are targets for GOTO jump commands -- with their help you can skip parts of the script (or, if you need to, repeat them), depending on whatever conditions are being met.
The label line itself has no other function than to mark the place, processing of the script resumes with the next line.
A label line consists of the word LABEL: followed by the name of the label. As everything in Hypatia labels are case insensitive. Label names cannot include spaces.
LABEL: somelabel
You can have as many labels in your script as you want. Hypatia does not check for duplicate labels -- if by mistake you use the same label name twice, only the first instance will ever be used.
GOTO interrupts the flow of the script execution and continues it after the specified label line:
GOTO somelabel
GOTO can be used after IF ... THEN, ALSO: and ELSE:, but also after I1: and (though I'm not sure if there will ever be a case for it) after I*:
The jump target (the specified label) can come after the GOTO command, but GOTO can also jump backwards in the script -- this creates a loop (see below).
The straightforward use of GOTO (where the target label comes after the GOTO command) is an alternative to long ALSO: or ALSO: ... ELSE: ... ALSO: sequences.
For instance:
IF $a IS0 THEN GOTO iszero
...
...
GOTO next
LABEL: iszero
...
...
LABEL: next
...
(Note in this example that IF $a IS0 ... is true when the value of $a is below the zero threshold. Alternatively IFNOT $a ... would only be true when $a is exactly zero.)
But GOTO can also address label lines that come before it, which offers the possibility of creating loops within a script, independent of Hypatia's DO and REPEAT loop commands (these will be discussed in chapter "Loops").
You have to use this feature with caution, because it can lead to an infinite loop -- while scripts running in an "infinite loop" (see the next chapter Loops) will eventually end after a given number of passes (one hundred thousand by default), Hypatia has no way to stop an out of control GOTO loop (you could only end it by closing Hypatia's console window).
With a GOTO loop your script needs to provide an exit -- this can happen in two ways.
One way is to have a command that exits the loop between the label line and the GOTO command (this can be SKIP, ABORT or another GOTO):
...
LABEL: loopstart
...
IF ... THEN GOTO loopend
...
GOTO loopstart
LABEL: loopend
...
(The labels loopstart and loopend are arbitray, you can use any names you want.)
Instead of GOTO loopend you could also use SKIP or ABORT to exit the loop, but these commands would immediately end execution of the script -- this would only make sense if the script ends with the GOTO loopstart command, for lines that come afterwards would never be reached.
The other way to provide a loop exit is to make the GOTO command at the end of the loop depend on an IF ... THEN or IFNOT ... THEN condition -- as long as it is met, the loop continues:
...
LABEL: loopstart
...
...
IF ... THEN GOTO loopstart
...
Without an exit condition the loop would only end when an error occurs, which, depending on the script, may or may not eventually happen.
More about all this in chapter Loops!
Home, Up: Scripts, Prev: IF ... THEN Conditions, Next: Comments