FORTRAN 77 Language Reference

GO TO (Computed)

The computed GO TO statement selects one statement label from a list, depending on the value of an integer or real expression, and transfers control to the selected one.

GO TO (s[, s])[,]e

Parameter 

Description 

s

Statement label of an executable statement

e

Expression of type integer or real  

Description

Execution proceeds as follows:

  1. e is evaluated first. It is converted to integer, if required.

  2. If 1 £ e £ n, where n is the number of statement labels specified, then the eth label is selected from the specified list and control is transferred to it.

  3. If the value of e is outside the range, that is, e < 1 or e > n, then the computed GO TO statement serves as a CONTINUE statement.

Restrictions

s must be in the same program unit as the GO TO statement.

The same statement label can appear more than once in a GO TO statement.

The statement control jumps to must be executable, not DATA, ENTRY, FORMAT, or INCLUDE.

Control cannot jump into a DO, IF, ELSE IF, or ELSE block from outside the block.

Example

Example: Computed GO TO


       ... 
       GO TO ( 10, 20, 30, 40 ), N
       ... 
10   CONTINUE 
       ... 
20   CONTINUE 
       ... 
40   CONTINUE 

:

In the above example: