TI-Basic Z80 Programming/Goto and Lbl
Goto ( CTL 0) and Lbl ( CTL 9) are used to jump to different sections in the program. However, these should be used sparingly, since having many Gotos can make the program very convoluted and difficult to understand.
Syntax and Usage
Lbl label Goto label
Where label is a one or two character code that only includes 0–9, A–Z, and θ.
When the program executes a Goto statement, it jumps to the corresponding Lbl with the same label. If the specified Lbl does not exist, a label error is thrown.
For example, observe the following program:
:Goto A :Lbl A :Disp "HI!" :Lbl B :Disp "HELLO!"
You may think that this program will display
HI!. However, the following is actually displayed:
This is because after the Disp command after the first Lbl, the program continues past the second Lbl and continues executing statements. To prevent the program from continuing to execute instructions, Stop ( CTL G) can be used, which simply stops the current program.
:Goto A :Lbl A :Disp "HI!" :Stop :Lbl B :Disp "HELLO!" :Stop
This modified program simply displays: