TI-Basic Z80 Programming/Goto and Lbl

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Goto and Lbl 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[edit]

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:

HI!
HELLO!

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, the Stop command (PRGM:CTL:G) can be used, which simply stops the current prorgam.

:Goto A
:Lbl A
:Disp "HI!"
:Stop
:Lbl B
:Disp "HELLO!"
:Stop

This modified prorgam simply displays:

HI!
Clipboard

To do:
Add example problems for using Lbl and Goto