GOTO

In this section:

How to:

Reference:

The GOTO command is used to transfer control to a different Maintain function, to a special point within the current function, or to terminate the application.

If you wish to transfer control to a different function, it is recommended that you use the PERFORM command instead of GOTO.


Top of page

x
Syntax: How to Use the GOTO Command

The syntax of the GOTO command is

GOTO destination [;]

where:

destination

Is one of the following:

functionname

Specifies the name of the function that control is transferred to. Maintain expects to find a function by that name in the procedure. You cannot use GOTO with a function that has parameters.

Top

Transfers control to the beginning of the Top function. All local variables are freed and current data source positions are retained, as are any uncommitted data source transactions.

END [KEEP|RESET]

Terminates the procedure. Control returns to whatever called the procedure. No function may be named END, as such a function would be ignored and never executed.

KEEP

Terminates a called procedure, but keeps its data (the values of its variables and data source position pointers) in memory. It remains in memory through the next call or, if it is not called again, until the application terminates.

RESET

Terminates a called procedure and clears its data from memory. This is the default.

EXIT

This is similar to GOTO END but immediately terminates all procedures in an application. This means that if one procedure calls another and the called procedure issues a GOTO EXIT, both procedures are ended by the GOTO EXIT command. No function may be named EXIT.

ENDCASE

Transfers control to the ENDCASE command in the function, and the function is exited. For information about the ENDCASE command, see CASE.

ENDREPEAT

Transfers control to the ENDREPEAT command in the current REPEAT loop. The loop is not exited. All appropriate loop counters specified on the ENDREPEAT command are incremented. For information about the REPEAT and ENDREPEAT commands, see REPEAT.

EXITREPEAT

Exits the current REPEAT loop. Control transfers to the next line after the ENDREPEAT command. For information about the REPEAT and ENDREPEAT commands, see REPEAT.

;

Terminates the command. Although the semicolon is optional, you should include it to allow for flexible syntax and better processing. For more information about the benefits of including the semicolon, see Terminating Command Syntax.

For example, to branch to the function named MainMenu, you would issue the command:

GOTO MainMenu

Top of page

x
Reference: Usage Notes for GOTO

Top of page

x
Reference: Commands Related to GOTO

Top of page

x
Using GOTO With Data Source Commands

A GOTO command can be executed in a MATCH command following an ON MATCH or ON NOMATCH command, or in NEXT following ON NEXT or ON NONEXT. The following syntax branches to the function MatchEdit when a MATCH occurs:

ON MATCH GOTO MatchEdit;

Top of page

x
GOTO and ENDCASE

When control is transferred to a function with the GOTO command, every condition for exiting that function must contain a command indicating where control should be passed to. If an ENDCASE command is reached by either GOTO or normal program flow, and Maintain has not received any instructions as to where to go next, Maintain takes a default action and exits the procedure. ENDCASE is treated differently when GOTO and PERFORM are combined. See PERFORM for more information.


Top of page

x
GOTO and PERFORM

It is recommended that you do not issue a GOTO command within the scope of a PERFORM command.

The scope of a PERFORM command extends from the moment at which it is issued to the moment at which control returns normally to the command or form control point immediately following it. The scope includes any additional PERFORM commands nested within it.

For example, if the Top function issues a PERFORM command to call Case One, Case One issues a PERFORM command to call Case Two. Case Two issues a PERFORM command to call Case Three, and control then returns to Case Two, returns from there to Case One, and finally returns to the Top function. You should not issue a GOTO command from the time the original PERFORM branches out of the Top function until it returns to the Top function.

If, when you code your application, you cannot know every potential run time combination of PERFORM and GOTO branches, it is recommended that you refrain from coding any GOTO commands in your application.


WebFOCUS