GO TO statement

The GO TO statement transfers control to the statement identified by the specified label reference. The GO TO statement is an unconditional branch.

Read syntax diagramSkip visual syntax diagramGO TOlabel;

Abbreviation: GOTO

label
Specifies a label constant, a label variable, or a function reference that returns a label value. Because a label variable can have different values at each execution of the GO TO statement, control might not always transfer to the same statement.

If a GO TO statement transfers control from within a block to a point not contained within that block, the block is terminated. If the transfer point is contained in a block that did not directly activate the block being terminated, all intervening blocks in the activation sequence are also terminated (see Procedure termination).

When a GO TO statement specifies a label constant contained in a block that has more than one activation, control is transferred to the activation current when the GO TO is executed (see Recursive procedures).

A GO TO statement cannot transfer control in the following ways:
  • To an inactive block. Detection of such an error is not guaranteed.
  • From outside a do-group to a statement inside a Type 2 or Type 3 do-group, unless the GO TO terminates a procedure or ON-unit invoked from within the do-group.
  • To a FORMAT statement.

If the destination of the GO TO is specified by a label variable, it can then be used as a switch by assigning label constants to the label variable. If the label variable is subscripted, the switch can be controlled by varying the subscript. By using label variables or function references, quite complex switching can be effected. It is usually true, however, that simple control statements are the most efficient. GOTO operations from one block to another block hinder many optimizations in the target block, unless the target label is the last statement in its block.