6.7. Do...Loop Until Repetition StatementThe Do...Loop Until repetition statement is similar to the Do Until...Loop statement, except that the loop-termination condition is tested after the loop body is performed; therefore, the loop body executes at least once. When a Do...Loop Until terminates, execution continues with the statement after the Loop Until clause. Figure 6.13 uses a Do...Loop Until statement to print the numbers from 1 to 5. Figure 6.13. Do...Loop Until repetition statement.
The Do...Loop Until statement activity diagram is the same as the one in Fig. 6.14. Note that the loop-termination condition (counter > 5) is not evaluated until after the body is executed at least once. If this condition is true, the statement exits. If the condition is false (i.e., the condition counter <= 5 is true), the loop continues executing. Figure 6.14. Do...Loop While repetition statement activity diagram.
Error-Prevention Tip 6.5
|