GO TO statement

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

GO TO label

The blank between GO and TO is optional. The label must identify a branch target statement (and not, for example, a declaration statement).

There is also a computed GOTO statement; this is error-prone and obsolescent since Fortran 95, so the CASE construct should be used instead. The syntax of the computed GOTO statement is as follows.

GO TO ( label [ , label ]... ) expression

The expression must be a scalar Integer.

There is also an assigned GOTO statement, but it is very error-prone and has therefore been deleted from Fortran 95. Its syntax is as follows.

GO TO variable-name [ ( label [ , label ]... ) ]

The variable-name must be a scalar Integer.

<Semantics>

The GOTO statement transfers control to the statement with the specified label. Note that transfer of control into a construct (such as a DO loop or IF-THEN) from outside is prohibited.

The computed GOTO statement transfers control to the ith label in the list, according to the value of the expression; if the value is less than one or greater than the number of labels in the list, execution continues with the statement following the computed GOTO.

The assigned GOTO statement transfers control to the last label assigned to the variable by the ASSIGN statement.

<Related>

ASSIGN statement, CASE construct, CONTINUE statement, CYCLE statement, DO construct, DO WHILE statement, END DO statement, EXIT statement