Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ASSIGN - Label Assignment

Statement: Assigns a statement label value to an integer variable. This feature has been deleted in the Fortran Standard. Intel® Fortran fully supports features deleted in the Fortran Standard.

ASSIGN label TO var

label

Is the label of a branch target or FORMAT statement in the same scoping unit as the ASSIGN statement.

var

Is a scalar integer variable.

When an ASSIGN statement is executed, the statement label is assigned to the integer variable. The variable is then undefined as an integer variable and can only be used as a label (unless it is later redefined with an integer value).

The ASSIGN statement must be executed before the statements in which the assigned variable is used.

Indirect branching through integer variables makes program flow difficult to read, especially if the integer variable is also used in arithmetic operations. Using these statements permits inconsistent usage of the integer variable, and can be an obscure source of error. The ASSIGN statement was used to simulate internal procedures, which now can be coded directly.

Example

The value of a label is not the same as its number; instead, the label is identified by a number assigned by the compiler. In the following example, 400 is the label number (not the value) of IVBL:

  ASSIGN 400 TO IVBL 

Variables used in ASSIGN statements are not defined as integers. If you want to use a variable defined by an ASSIGN statement in an arithmetic expression, you must first define the variable by a computational assignment statement or by a READ statement, as in the following example:

  IVBL = 400 

The following example shows ASSIGN statements:

  INTEGER ERROR
  ...
  ASSIGN 10 TO NSTART
  ASSIGN 99999 TO KSTOP
  ASSIGN 250 TO ERROR

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

The following statement associates the variable NUMBER with the statement label 100:

  ASSIGN 100 TO NUMBER

If an arithmetic operation is subsequently performed on variable NUMBER (such as follows), the runtime behavior is unpredictable:

  NUMBER = NUMBER + 1

To return NUMBER to the status of an integer variable, you can use the following statement:

  NUMBER = 10

This statement dissociates NUMBER from statement 100 and assigns it an integer value of 10. Once NUMBER is returned to its integer variable status, it can no longer be used in an assigned GO TO statement.