GOTO
The GOTO
instruction transfers program
control to a labeled line within the same program block.
Syntax
GOTO [:] label-id
- label-id is the name of the
LABEL
statement to jump to.
Usage
A GOTO
statement continues program execution in the line following the LABEL
instruction using the
label-id identifier specified in the GOTO
instruction.
The LABEL
jump
point can be defined before or after the GOTO
statement.
The LABEL
and GOTO
statements must use the
label-id within a single MAIN
, FUNCTION
, or REPORT
program block.
Note: The
:
colon after the GOTO
keyword is optional.GOTO
statements can reduce the readability of your program source and result
in infinite loops. Use FOR
, WHILE
and CASE
statements instead.
The GOTO
statement can be used
in a WHENEVER
statement to handle exceptions.
Example
MAIN
DEFINE exit_code INTEGER
DEFINE l_status INTEGER
WHENEVER ANY ERROR GOTO _error
DISPLAY 1/0
GOTO _noerror
LABEL _error:
LET l_status = STATUS
DISPLAY "The error number ", l_status, " has occurred."
DISPLAY "Description: ", err_get(l_status)
LET exit_code = -1
GOTO _exit
LABEL _noerror:
LET exit_code = 0
GOTO _exit
LABEL _exit:
EXIT PROGRAM exit_code
END MAIN