Top > Lycia reference > Querix 4GL > Statements > EXIT
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.
EXIT statement is used to terminate the execution of a compound 4GL statement (a block, a loop, etc.) and to pass the program control to the first statement following the END keyword of the corresponding statement. When 4GL encounters the EXIT keyword, the part of the compound statement located between the EXIT keyword and the END keyword is skipped. The following statements can be combined with the EXIT statement:
Element |
Description |
Exit Code |
A 4GL expression that returns a positive integer no greater than 256 |
The EXIT statement is also used to terminate the program. The EXIT PROGRAM statement is used to terminate the currently running program, the other EXIT statements do not terminate the program. They only transfer the control out of the current program structure.
4GL statements present in the diagram above support the EXIT keyword. The EXIT statement keywords transfer the control to the first statement that follows the END statement keywords.
To terminate the DISPLAY ARRAY statement, the EXIT DISPLAY keywords are used. To terminate both INPUT and INPUT ARRAY statements, the EXIT INPUT keywords are used.
The EXIT statements can appear only in the corresponding statements. E.g. EXIT WHILE statement can appear only within the WHILE loop, which will transfer the control to the first statement following the END WHILE keywords.
You can use the EXIT keyword to leave a function. However, if the EXIT FUNCTION statement is executed, nothing is passed to the calling routine, thus this method cannot be used if you want to return values from a function.
The RETURN keyword performs the function of EXIT statement and returns one or more values to the calling routine. The GO TO and WHENEVER GO TO statements cannot transfer control out of the FUNCTION program block.
Unlike other EXIT statements, the EXIT PROGRAM statement terminates not a separate program block or compound statement but the program itself. It can occur in any part of the source code and is not linked to a certain statement.
In the example below the EXIT PROGRAM statement is used within the MENU statement.
MENU "Main Menu"
...
COMMAND "Exit" "Close the program"
EXIT PROGRAM
END MENU
The other example shows the usage of the EXIT PROGRAM statement in an ON KEY block
DISPLAY ARRAY my_arr TO my_scrarr.*
...
ON KEY (F20)
MESSAGE "You now will exit the program"
SLEEP 1
EXIT PROGRAM
END DISPLAY
The effect of the EXIT PROGRAM is the same as the effect of the END MAIN statement, both terminate the program.
Exit Code
EXIT PROGRAM keywords can be followed by the exit code. It can be any whole number less than 256. This exit code value is saved if a program has been run with the help of the RUN statement with the RETURNING clause. The exit code value is returned as an integer that needs 2 bytes for storage; it contains the information on the termination status of the program:
The low byte specifies the termination status of the program executed with the help of the RUN statement. The value of this status can be calculated by using the formula: integer value modulo 256.
The high byte contains the low byte from the EXIT PROGRAM statement of the program executed by the RUN statement. Its value can be recovered by dividing the integer value by 256.