Flow-control structures: Difference between revisions

m
(→‎{{header|Fortran}}: Even worse behaviour is possible.)
Line 527:
Fortran offers <code>GO TO ''label''</code> where ''label'' is a number, an integer, which is prefixed to some executable statement according to the rules of Fortran source layout. Fortran has no reserved words and gives no significance to spaces, so that <code>G O TO 12 3 4</code> is just as valid as <code>GO TO 1234</code> and other usages. As a result of this, text labels are difficult to fit into the syntax so that the likes of <code>GO TO START</code> are unavailable. However, a compiler may offer the "assigned GO TO" facility, with statements such as <code>ASSIGN 120 TO THENCE</code> scattered about: 120 is a statement label, not an integer, and any statement label may be assigned to variable THENCE (which is an integer variable) as execution proceeds. Then <code>GO TO THENCE</code> will cause a GO TO for the current address held in THENCE... Should you yield to temptations such as <code>THENCE = THENCE - 6</code> (treating it as an ordinary integer), a subsequent <code>GO TO THENCE</code> may end execution with an error message, or something else...
 
This sort of behaviour actually can be put to a positive use to handle the situation where in a large programme there may be portions that could be put to useemployed from a number of locations, and one does not wish to repeat that code each time.<lang Fortran> ...
ASSIGN 1101 to WHENCE !Remember my return point.
GO TO 1000 !Dive into a "subroutine"
1,220

edits