Top  >  Lycia reference  >  Querix 4GL  >  Statements  >  EXIT

EXIT

 

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.

 

 

Exiting a Compound Statement

 

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.

 

 

Exiting a Function

 

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.

 

 

Exiting a Program

 

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: