< TI-Basic Z80 Programming

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

Lbl ''label''
Goto ''label''

Where label is a one or two character code that only includes 09, AZ, 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!

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.