GOTO
Valid in: DBProc, TblProc
The GOTO label_name statement unconditionally branches to a statement following a label declaration. The label must be unique within its scope and precede a statement.
The GOTO label_name statement has the following format:
GOTO label_name;
A label declaration is specified by a unique alphanumeric identifier enclosed within '<<' and '>>', as in the following:
<<label_name>> statement;
A label declaration can be used before any statement, including a label that names a FOR, WHILE, or REPEAT loop. If a label declaration precedes an unlabelled FOR, WHILE, or REPEAT loop, the label_name can be used with the ENDLOOP statement to indicate which loop to break out of.
The GOTO label_name causes control to switch to the first statement following the label. A procedure will not be created if the label_name of a GOTO statement is not declared.
The following example illustrates the use of labels:
<<label_1>> <<label_2>> label_3: WHILE condition_1 DO
statement_list_1
<<label_4>> FOR select_1 DO
statement_list_2;
<<label_5>> statement_list_3;
IF condition_2 THEN
GOTO label_5;
ELSEIF condition_3 THEN
GOTO label_1;
ELSEIF condition_4 THEN
GOTO label_3;
ELSEIF condition_5 THEN
GOTO label_6;
ELSEIF condition_6 THEN
ENDLOOP label_3;
ELSEIF condition_7 THEN
ENDLOOP label_4;
ENDIF;
statement_list_4
ENDFOR;
statement_list_5
ENDWHILE;
statement_list_6
<<label_6>>
statement_list_7
In this example, the two forms of labels are used to name a loop ('label_3' and '<<label_4>>'). If condition_4 is true, then control switches back to the WHILE, but if condition_6 is true, control resumes at statement_list_6.
Multiple labels can be specified before a statement, so here 'GOTO label_1', 'GOTO label_2' and 'GOTO label_3' switch control to the WHILE statement.
Permissions
You must have CREATE_PROCEDURE privilege.
Last modified date: 08/29/2024