The computed GOTO statement causes transfer of control to one of a list of labeled statements.
SyntaxGO TO ( labels ) [,] scalar-int-exprWhere:
labels is a comma-separated list of labels.
scalar-int-expr is a scalar INTEGER expression.
Execution of a computed GOTO statement causes evaluation of
scalar-int-expr. If this value is i such that
Each label in labels must be the label of a branch target statement in the current scoping unit.
The computed GOTO statement has been identified as a major contributor to a logic-snarled condition known as "spaghetti code", which makes a program difficult to read and debug. The computed GOTO statement is best replaced by the CASE Construct although the IF Construct could be used as well. Although the computed GOTO statement is obsolescent and should never be used when writing new code, it is fully supported.
Exampleinteger :: i=1 40 write(*,*) " computed goto construct" goto (20,30,40) i write(*,*) " transfer here if no match" goto 10 30 write(*,*) " if i=2 control transfers here" 20 write(*,*) " if i=1 control transfers here" 10 write(*,*) " equivalent case construct" select case (i) case(1) write(*,*) " if i=1 control transfers here" case(2) write(*,*) " if i=2 control transfers here" case(3) write(*,*) " if i=3 control transfers here" case default write(*,*) " transfer here if no match" end select