5.6.2 Computed GO TO Statement

The computed GO TO statement transfers control to a statement based on the value of an expression within the statement. It takes the following form:

GO TO (slist)[,] e
slist
Is a list of one or more labels of executable statements separated by commas. The list of labels is called the transfer list.
e
Is an arithmetic expression in the range 1 to n (where n is the number of statement labels in the transfer list).

Rules and Behavior

The computed GO TO statement evaluates the expression e and, if necessary, converts the resulting value to integer data type. Control is transferred to the statement label in position e in the transfer list. For example, if the list contains (30,20,30,40) and the value of e is 2, control is transferred to statement 20.

If the value of e is less than 1 or greater than the number of labels in the transfer list, control is transferred to the first executable statement after the computed GO TO statement.

Examples

The following examples show valid computed GO TO statements:

GO TO (12,24,36), INDEX

GO TO (320,330,340,350,360), SITU(J,K) + 1


Previous Page Next Page Table of Contents