next up previous contents
Next: Shared DO-loop Termination Up: Obsolescent Features Previous: PAUSE Statement

REAL and DOUBLE PRECISION DO-loop Variables

In FORTRAN 77 REAL and DOUBLE PRECISION variables can be used in DO-loop control expressions and index variables. This is unsafe because a loop with real valued DO-loop control expressions could easily iterate a different number of times on different machines -- a loop with control expression 1.0,2.0,1.0 may loop 1 or 2 times because real valued numbers are only stored approximately, 1.0 + 1.0 could equal, say, 1.99, or 2.01. The first evaluation would execute 2 times whereas the second would only give 1 execution. The solution to this problem is to use INTEGER variables and construct REAL or DOUBLE PRECISION variables within the loop.

The following loop is obsolescent:

    DO x = 1.0,2.0,1.0
     PRINT*, INT(x)
    END DO
    PRINT*, x


next up previous contents
Next: Shared DO-loop Termination Up: Obsolescent Features Previous: PAUSE Statement

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.