Formal Definition
The next statement is used to complete execution of one of the iterations of an enclosing loop statement. The completion is conditional if the statement includes a condition.
Simplified Syntax
next;
next loop_label;
next loop_label when condition;
Description
The next statement allows to skip a part of an iteration loop. If the condition specified after the when reserved word is TRUE, or if there is no condition at all, then the statement is executed. This results in skipping all statements below it until the end of the loop and passing the control to the first statement in the next iteration (example 1).
A next statement may specify the name of the loop it is expected to influence. If no label is supported then the statement applies to the innermost enclosing loop (example 2)
Examples
Example 1
Loop_Z: for count_value in 1 to 8 loop
Assign_1: A(count_value) := '0';
next when condition_1;
Assign_2: A(count_value + 8) := '0';
end loop Loop_Z;
If the condition_1 in the iteration count_value is TRUE, then the next statement will be executed. The next statement to be executed will be Assign_1 in the iteration count_value+1. Otherwise, the sequence of operations is as specified, i.e. Assign_2 is executed.
Example 2
Loop_X: for count_value in 1 to 8 loop
Assign_1: A(count_value) := '0';
k := 0;
Loop_Y: loop
Assign_2: B(k) := '0';
next Loop_X when condition_1;
Assign_3: B(k + 8) := '0';
k := k + 1;
end loop Loop_Y;
end loop Loop_X;
If condition_1 is TRUE, then the next statement is executed and the control goes to the assignment statement labeled Assign_1 in the next iteration of Loop_X. If not, then the iteration is continued with Assign_3, causing incrementing k.
Important Notes
· The next statement is often confused with the exit statement. The difference between the two is that the exit statement "exits" the loop entirely, while the next statement skips to the "next" loop iteration (in other words, it "exits" the current iteration of the loop).
No comments:
Post a Comment