Loop Constructs

Loops can be formed with the usual DO-ENDDO and DO WHILE, or by using a 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.

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

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) GOTO 10
I = I + 1
ENDDO
10 CONTINUE
RETURN
END