Visal Basic per Begginer

Page 130

111 Do

For a better look at the differences, compare the following do loops. liCounter = 25

picOutput.Print liCounter Loop

liCounter = 25 Do picOutput.Print liCounter Loop While liCounter < 20

You should now be able to see that the second loop’s inner statements will execute once, where the first looping construct will not.

Loop Until Another popular way to implement a do loop is with the loop until structure. Like the do while structure, loop until uses a condition to loop or not loop. However, unlike the do while loop, the loop until structure evaluates its condition after the loop has executed. What this essentially means is that you are guaranteed your loop’s statements will execute at least once with the loop until structure. Here’s the basic syntax for the loop until structure: Do ‘statements Loop Until Condition

As mentioned earlier, loop until structures are useful when you know for certain that you want the loop’s contents to execute at least once. HIN

T

This can also be accomplished with the condition While when placed at the end of a do loop construct.

Here’s another example of a loop until structure that displays a menu until the user chooses to quit: Do ‘display menu ‘process menu selection

Iteration

Do While liCounter < 20

Chapter 4

picOutput.Print liCounter Loop While liCounter < 20


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.