END LOOP
The END LOOP statement marks the end of loop execution.
END LOOP
(1)
(2)
(2) Loop index (A to Z, AI to ZI) |
The parameter entered is a predefined field A to Z or AI to ZI that corresponds to the index counter specified in the matching BEG LOOP statement.
If the index counter plus the step value is outside the to range set in the BEG LOOP statement, the index counter is left unchanged, and execution continues with the statement following the END LOOP.
Otherwise, the index counter is incremented by the step value, and execution continues with the statement immediately following the corresponding BEG LOOP statement.
A BEG LOOP statement must come before the END LOOP statement. There must be an END LOOP statement for each BEG LOOP statement. See the BEG LOOP section for additional information.
An error occurs if a BEG LOOP statement does not get executed.
The following example is a simple loop that increments the current monthly budgets by 5 percent for all 12 months:
BEG
LOOP AI = 001 TO 012 STEP 001
COMPUTE TGL
BUDGET AMOUNT AI * 1.05
END LOOP AI
After the twelfth repetition (where AI=12), control is passed to the next statement following the END LOOP statement.
The next example presents a nested loop that repeats its processing logic within each occurrence of the main loop. This loop also incorporates a conditional check to see if the value of field C equals that of field D, at which point the internal loop terminates and returns control to the main loop.
BEG
LOOP A = 001 TO 010 STEP 001
*
* (Perform
processing if needed)
*
BEG LOOP B =
001 TO 005 STEP 001
*
* (Perform
processing)
*
IF ---
C EQ
--- D
T SET ---
B = 5
END LOOP B
*
END LOOP A
There can be more BEG LOOP statements in an ILF routine than END LOOP statements. For example:
T BEG
LOOP A = 001 TO 010 STEP 001
F BEG LOOP A =
001 TO 005 STEP 001
*
* (Perform
processing)
*
END LOOP A
In the preceding example, only one of the BEG LOOP statements can execute.