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

GOTO

 

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:

 

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:

 

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.