Loop Constructs

Loops can be formed with the usual DO-END DO and DO WHILE, or by using an IF/GOTO and a label. However, the loops must have a single entry and a single exit to be vectorized. Following are the examples of correct and incorrect usages of loop constructs.

Example 1: Correct Usage

SUBROUTINE FOO (A, B, C)
DIMENSION A(100),B(100), C(100)
INTEGER I
I = 1
DO WHILE (I .LE. 100)
 A(I) = B(I) * C(I)
   IF (A(I) .LT. 0.0) A(I) = 0.0
     I = I + 1

    ENDDO
 RETURN
END

 

Example 2: Incorrect Usage

SUBROUTINE FOO (A, B, C)
DIMENSION A(100),B(100), C(100)
INTEGER I
I = 1
DO WHILE (I .LE. 100)
 A(I) = B(I) * C(I)
C The next statement allows early
C exit from the loop and prevents
C vectorization of the loop.
IF (A(I) .LT. 0.0) GO TO 10
 I = I + 1
ENDDO
10 CONTINUE
RETURN
END