Loop exit conditions determine the number of iterations that a loop executes. For example, fixed indexes for loops determine the iterations. The loop iterations must be countable; that is, the number of iterations must be expressed as one of the following:
A constant
A loop invariant term
A linear function of outermost loop indices
Loops whose exit depends on computation are not countable. Examples below show countable and non-countable loop constructs.
Example 1: Correct Usage for Countable Loop |
---|
SUBROUTINE FOO (A, B, C, N, LB) |
Example 2: Correct Usage for Countable Loop |
---|
! Number of iterations is (N-M+2)/2 |
Example 3: Incorrect Usage for Non-Countable Loop |
---|
! Number of iterations is dependent on A(I) |