Do While Loop in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes how to use Do While loops in Visual Basic .NET

One of the Do Loop statements variations is the Do While and it executes as long as a condition is true (while a particular condition is true).

Its syntax is as follows:

Do {While} condition
    statements
[Exit Do]
    statements
Loop
                    



This While loop keeps running as long as the expression is True. As soon as the expression becomes False, it stops.

                    
Dim array() As Integer = {1, 3, 5, 7, 10, 20, 50}
Dim counter As Integer = array.GetUpperBound(0) + 1
Do While counter > 0
    counter -= 1
    'print the array elements
    Console.WriteLine(array(counter))
Loop 
 ' this loop prints out all the array elements
 


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.