TI-Basic Z80 Programming/Goto and Lbl

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

Goto (PRGM CTL 0) and Lbl (PRGM 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[edit | edit source]

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, Stop (PRGM 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:

HI!

Previous: GetKey
Next: Menus
Table of Contents: TI-Basic Z80 Programming