Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

Iteration Loop Control

DO iteration loop control takes the following form:

do-var = expr1, expr2 [, expr3]

do-var

Is the name of a scalar variable of type integer or real. It cannot be the name of an array element or structure component.

expr

Is a scalar numeric expression of type integer, logical, or real. If it is not the same type as do-var, it is converted to that type.

Description

A DO variable or expression of type real is a deleted feature in the Fortran Standard. Intel® Fortran fully supports features deleted in the Fortran Standard.

The following steps are performed in iteration loop control:

  1. The expressions expr1, expr2, and expr3 are evaluated to respectively determine the initial, terminal, and increment parameters.

    The increment parameter (expr3) is optional and must not be zero. If an increment parameter is not specified, it is assumed to be of type default integer with a value of 1.

  2. The DO variable (do-var) becomes defined with the value of the initial parameter (expr1).

  3. The iteration count is determined as follows:

          MAX(INT((expr2 - expr1 + expr3)/expr3), 0)

    The iteration count is zero if either of the following is true:

          expr1 > expr2 and expr3 > 0
          expr1 < expr2 and expr3 < 0
  4. The iteration count is tested. If the iteration count is zero, the loop terminates and the DO construct becomes inactive. (Compiler option f66 can affect this.) If the iteration count is nonzero, the range of the loop is executed.

  5. The iteration count is decremented by one, and the DO variable is incremented by the value of the increment parameter, if any.

After termination, the DO variable retains its last value (the one it had when the iteration count was tested and found to be zero).

The DO variable must not be redefined or become undefined during execution of the DO range.

If you change variables in the initial, terminal, or increment expressions during execution of the DO construct, it does not affect the iteration count. The iteration count is fixed each time the DO construct is entered.

Examples

The following example specifies 25 iterations:

  DO 100 K=1,50,2

K=49 during the final iteration, K=51 after the loop.

The following example specifies 27 iterations:

  DO 350 J=50,-2,-2

J=-2 during the final iteration, J=-4 after the loop.

The following example specifies 9 iterations:

  DO NUMBER=5,40,4

NUMBER=37 during the final iteration, NUMBER=41 after the loop. The terminating statement of this DO loop must be END DO.

See Also