Working with Loops

The other major type of control statement is the loop. You use loops to perform repetitive tasks in your program. Each time the task repeats, the loop is said to have completed an iteration. The three main types of loops are supported by Visual Basic: counter loops, conditional loops, and enumerator loops. Counter, or For, loops perform a task a set number of times. Conditional, or Do, loops perform a task while a specified condition exists or until a specified condition exists. Enumerator loops are used to perform an action on each item in a group of objects. Each of these types of loops is discussed in the following sections.

For Loops

A counter loop also is known as a For loop, or a For/Next loop, because the ends of the ...

Get Special Edition Using Microsoft® Visual Basic® .NET 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.