Skip to content

Goto

Purpose

To move execution to a labeled address of the program.

Syntax

Goto {label}

What It Does

The Goto command transfers execution to a labeled command line. The following program demonstrates how the Goto command can be used to exit a loop.

Example

String sValue sTest
Integer iCount
Move "hello world" To sValue
For iCount From 1 To (length(sValue))
    Move (Mid(sValue, 1, iCount)) To sTest
    // If the character 'w' is found, quit the loop.
    If (sTest = 'w') Begin
        Showln "found a 'w'"
        Goto Label
    End
    Else; // show progress
        Showln "Character number " iCount " is a [" sTest "]"
Loop
Label:
Showln "There is almost never a reason to use a Goto"

Notes

  • It is good programming style to use procedures and functions or break in preference to Goto whenever possible. Since the break statement only exits from one level of a loop, a Goto may be necessary for exiting a loop from within a deeply nested loop.

  • We do not recommend using the Goto command, because programs can become quite error-prone when it is used.