GO TO (computed)

Purpose

The computed GO TO statement transfers program control to one of possibly several executable statements.

Syntax

Read syntax diagramSkip visual syntax diagramGO TO(stmt_label_list ),arith_expr
stmt_label
is the statement label of an executable statement in the same scoping unit as the computed GO TO. The same statement label can appear more than once in stmt_label_list.
arith_expr

is a scalar integer expression.

It can also be real or complex. If the value of the expression is noninteger, XL Fortran converts it to INTEGER(4) before using it.

Rules

When a computed GO TO statement is executed, the arith_expr is evaluated. The resulting value is used as an index into stmt_label_list. Control then transfers to the statement whose statement label you identify by the index. For example, if the value of arith_expr is 4, control transfers to the statement whose statement label is fourth in the stmt_label_list, provided there are at least four labels in the list.

If the value of arith_expr is less than 1 or greater than the number of statement labels in the list, the GO TO statement has no effect (like a CONTINUE statement), and the next statement is executed.

Examples

      INTEGER NEXT
         ...
      GO TO (100,200) NEXT
10    PRINT *,'Control transfers here if NEXT does not equal 1 or 2'
         ...
100   PRINT *,'Control transfers here if NEXT = 1'
         ...
200   PRINT *,'Control transfers here if NEXT = 2'

Related information