Goto

Goto performs an unconditional branch from a script to another label.

Syntax

 Goto LABELGoto LABEL From SCRIPTGoto LABEL FROM =STRING_EXPR

The script can be prefixed by the folder code followed by a dot when it is only an evaluated script. If not, the script is searched in the folder. If the script is not found in the folder then the search is carried out in the hierarchy of folders given by the adxmother variable in ascending order.

Examples

# Example 1: The first label is called by a Gosub an returns a value for I depending on J# The resulting values for I will be:# If J=0, I=6; If J=1, I=6; If J=1, I=5; If J=3 to 99, I=3, If J is negative or over 100, I=10# J=0 : I=6# J=0 : I=6$GET_VALUELocal Integer II=0If J=0 : Goto J0Elsif J=1 : Goto J1Elsif J=2 : Goto J2Elsif J<100 : Goto J3EndifI+=4$J0$J1 : I+=1J2 : I+=2J3 : I+=3Return# If a fatal error happens, perform some actions in another script with no return# The script name is ERROR_HANDLER_ followed by the error valueIf ERROR_STATUS>FATAL_ERRORGoto ERROR From ="ERROR_HANDLER_"+num$(ERROR_STATUS)Endif

Description and comments

The Goto instruction performs an unconditional jump. It breaks the execution order of a script that will execute the line in sequential order.

All the context is shared, especially:
* The local variable class.
* The default class list of values.
* The tables and joins opened.
* The transaction in progress. In a script where a branch has been done by Goto, you can commit a transaction that has been opened in the calling script, which is not the case if the script is called by Call, func, or fmet.
* The error handler set by Onerrgo.

Comments

As a lot of code nesting instructions exist (If..Elsif..Else..Endif, While..Wend, Repeat..Until, Case.. When.. WhenDefault.. Endcase, For.. Next, Break), using Goto is the outdated method of writing code and difficult to read. It should therefore be avoided.

A given label must be unique in a given script (this is also checked at compilation time).

Associated errors

Error codeDescription
20Script does not exist or cannot be accessed (Goto ... From syntax), or label does not exist in the corresponding script.

See also

Gosub, Return, Call, Subprog, Funprog, func, fmet.