Top > Lycia reference > Querix 4GL > Statements > GOTO
To meet your needs, we constantly work to improve Querix products.
This means that Lycia documentation is developing as well.
In case you have found a certain dissonance between the provided information and the actual behavior of Lycia 3 and/or your applications, please, let us know about this via documentation@querix.com so that we can introduce the necessary changes to our documentation.
Thank you for your attention and cooperation.
GOTO statement is used to transfer program control within the range of the same program block. It transfers the control to the place where the corresponding LABEL statement is located.
Element |
Description |
Label-name |
The name of a previously declared label |
When 4GL encounters the GOTO statement, it transfers control to the LABEL statement, where the identifiers are the same. It begins executing the first statement that follows the LABEL statement skipping all the statements that follow the GOTO statement. The corresponding LABEL statement can be located anywhere in the same program block, either above the GOTO statement or below it. See also the section about the "LABEL" statement.
The GOTO statement can transfer program control to the LABEL statement only if:
The GOTO and the LABEL statement have the same label-name
The GOTO and LABEL statement occur within the same program block (MAIN, FUNCTION or REPORT)
It is not advisable that you overuse the GOTO and LABEL statements, it may lead to difficulties in reading and maintaining the code and in infinite loops. There are alternative methods of transferring program control, they are:
CASE, FOR, IF and WHILE statements with Boolean expressions
CALL, OUTPUT TO REPORT and WHENEVER statements
EXIT keyword with the corresponding statement which terminates this statement (see the section on the "EXIT" keyword)
The CONTINUE keyword with the corresponding statement (see the section of the "CONTINUE" statement)
The GOTO statement can prove useful in the situations when you need to exit from a deeply nested loop:
LABEL retry:
…
FOR i = 1 TO 20
FOR a = 5 TO 15
…
IF ent_val <0 THEN
GOTO :retry
ELSE
…
END IF
END FOR
END FOR
You can also place a colon before the label-name in the GOTO statement to indicate that it conforms to the ANSI standard.