Loops

As in the previous versions of the language, Visual Basic 2010 offers two kinds of loops: Do..Loop and While..End While. In this section we take a look at both loops.

Do..Loop

The Do..Loop is the most used loop in Visual Basic and the most flexible. Basically such a loop can have two behaviors: repeating a set of actions until a condition is false and repeating a set of actions until a condition is true. The first scenario is accomplished using a Do While statement, as demonstrated in Listing 4.3.

Listing 4.3 Performing a Do While Loop

image

The code is quite easy: Whereas the value of max is less than the maximum value of the Integer type, increment ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.