- 2073 Chaitra · 3 marks
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
| Basis | Unconditional GO TO | Computed GO TO |
|---|---|---|
| Destination | Single label | One of many labels |
| Condition | None | Value of an integer expression |
| Acts like | A simple jump | A multi-way switch |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Formatted I/O in FORTRAN with syntax · Computer Programming, chapter 11
- GOTO types; sum of series program · Computer Programming, chapter 11
- Two dimensional arrays in FORTRAN · Computer Programming, chapter 11