Skip to main content

Unconditional and computed GOTO

Short answer

Unconditional GO TO (GO TO label) always transfers control to one label. Computed GO TO (GO TO (lab1, lab2, ...), expr) chooses a label based on an integer expression value (1 jumps to lab1, etc.), acting as a multi-way switch.

Compare unconditional goto and computed goto in FORTRAN with syntax.

Unconditional GO TO transfers control to one fixed labelled statement, always.

Syntax: GO TO label

      GO TO 50
   ...
   50 PRINT *, 'JUMPED HERE'

Computed GO TO chooses one of several labels depending on the value of an integer expression.

Syntax: GO TO (label1, label2, ..., labeln), integer_expression

If the expression is 1, control goes to label1; if 2, to label2, and so on. If the value is less than 1 or greater than n, no jump is made and the next statement runs.

      READ *, K
      GO TO (10, 20, 30), K
   10 PRINT *, 'ONE'
      STOP
   20 PRINT *, 'TWO'
      STOP
   30 PRINT *, 'THREE'
      END
BasisUnconditional GO TOComputed GO TO
DestinationSingle labelOne of many labels
ConditionNoneValue of an integer expression
Acts likeA simple jumpA multi-way switch

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →