Menu

VB.NET TUTORIALS - VB.Net - Loops

VB.Net - Loops

ADVERTISEMENTS

Loop TypeDescription
Do LoopIt repeats the enclosed block of statements while a Boolean condition is True or until the condition becomes True. It could be terminated at any time with the Exit Do statement.
For...Next It repeats a group of statements a specified number of times and a loop index counts the number of loop iterations as the loop executes.
For Each...Next It repeats a group of statements for each element in a collection. This loop is used for accessing and manipulating all elements in an array or a VB.Net collection.
While... End WhileIt executes a series of statements as long as a given condition is True.
With... End WithIt is not exactly a looping construct. It executes a series of statements that repeatedly refer to a single object or structure.
Nested loopsYou can use one or more loops inside any another While, For or Do loop.

ADVERTISEMENTS

Loop Control Statements:

Control StatementDescription
Exit statementTerminates the loop or select case statement and transfers execution to the statement immediately following the loop or select case.
Continue statementCauses the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
GoTo statementTransfers control to the labeled statement. Though it is not advised to use GoTo statement in your program.

ADVERTISEMENTS