Visual Basic 2005 for Programmers (2nd Edition)
5.6. Do While...Loop Repetition Statement
The Do While...Loop repetition statement behaves like the While repetition statement. As an example of a Do While...Loop statement, consider another version of the program designed to find the first power of 3 larger than 100 (Fig. 5.6). Figure 5.6. Do While...Loop repetition statement demonstration.
When the Do While...Loop statement is entered (line 9), the value of product is 3. The variable product is repeatedly multiplied by 3, taking on the values 3, 9, 27, 81 and 243, successively. When product becomes 243, the condition in the Do While...Loop statement, product <= 100, becomes false. This terminates the repetition, with the final value of product being 243. Program execution continues with the next statement after the Do While...Loop statement. Because the While and Do While...Loop statements behave in the same way, the activity diagram in Fig. 5.5 also illustrates the flow of control of the Do While...Loop repetition statement. Common Programming Error 5.2
|