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 linear function of an integer variable
a loop invariant term
Loops whose exit depends on computation are not countable. Examples below show countable and non-countable loop constructs.
Correct Usage for Countable Loop, Example 1 |
SUBROUTINE FOO (A, B, C, N, LB) |
Correct Usage for Countable Loop, Example 2 |
! Number of iterations is (N-M+2) /2 |
Incorrect Usage for Non-countable Loop |
! Number of iterations is dependent on A(I) |