GOTO

The GOTO statement transfers program control to a labeled line within the same program block.

4GLREF00000150.gif

label name is a statement label that you declare in a LABEL statement.

The GOTO statement transfers control of execution within a program block. Upon encountering this statement, 4GL jumps to the statement immediately following the specified LABEL statement, and resumes execution there, skipping any intervening statements that lexically follow the GOTO statement.

These rules apply to the use of the GOTO and LABEL statements:

To transfer control to a labeled line, the GOTO statement must use the same label name as the LABEL statement above the desired line.

Both statements must reside in the same MAIN, FUNCTION, or REPORT block. You cannot use GOTO to transfer into or out of a program block.

Excessive use of GOTO statements in 4GL (or any programming language) can make your code difficult to read or to maintain, or can result in a loop that has no termination. Many situations in which you need to transfer control of program execution can be solved by using one of the following alternatives to the GOTO statement:

Boolean expressions and the CASE, FOR, IF, and WHILE statements.

The EXIT keyword in blocks within the following statements:

CASE
FOREACH
MENU
DISPLAY ARRAY
INPUT
WHILE
FOR
INPUT ARRAY

 
The CONTINUE keyword in blocks within the following statements:

FOR
INPUT
MENU
FOREACH
INPUT ARRAY
WHILE
The CALL statement

The WHENEVER statement.

References

CASE

FOR

FUNCTION

IF

LABEL

MAIN

REPORT

WHENEVER

WHILE