3.5 ASSIGN Statement

The ASSIGN statement assigns a statement label value to an integer variable. The variable can then be used as either a transfer destination in a subsequent assigned GO TO statement or a format specifier in a formatted I/O statement. ASSIGN statements take the following form:

ASSIGN s TO v
s
Is the label of an executable statement or a FORMAT statement in the same program unit as the ASSIGN statement.
v
Is an integer variable.

The ASSIGN statement assigns the statement number to the variable. It is similar to an arithmetic assignment statement with one exception: the variable becomes defined as a statement label reference and undefined as an integer variable.

An ASSIGN statement must be executed before the statements in which the assigned variable is used. The ASSIGN statement and the statements in which the assigned variable is used also must occur in the same program unit; for example:

ASSIGN 100 TO NUMBER

This statement associates the variable NUMBER with the statement label 100. Once the ASSIGN statement associates a statement label to a variable, arithmetic operations on the variable produce unpredictable run-time behavior; for example:

NUMBER = NUMBER + 1

To return the variable to the status of an integer variable, you could use the following statement, which dissociates NUMBER from statement 100 and assigns it an integer value of 10:

NUMBER = 10

Once returning the variable NUMBER to its integer variable status, it can no longer be used in an assigned GO TO statement.

Examples

The following additional examples show valid ASSIGN statements:

ASSIGN 10 TO NSTART

ASSIGN 99999 TO KSTOP

ASSIGN 250 TO ERROR

NSTART and KSTOP are integer variables implicitly, but ERROR must be previously defined as an integer variable.

The following example shows invalid use of the ASSIGN statement:

ASSIGN 10 TO I
J = I
GO TO J

In this case, variable J is not the variable assigned to, so it cannot be used in the assigned GO TO statement.


Previous Page Next Page Table of Contents