How to use While End While loop

Whenever you face a situation in programming to repeat a task for several times (more than one times ) or you have to repeat a task till you reach a condition, in these situations you can use loop statements to achieve your desired results.

VB.NET while loop

While ..End While

While .. End While Loop execute the code body (the source code within While and End while statements ) until it meets the specified condition. The expression is evaluated each time the loop is encountered. If the evaluation result is true, the loop body statements are executed.

Condition : The condition set by the user

  1. Line 1: Counter start from 1
  2. Line 2: While loop checking the counter if it is less than or equal to 10
  3. Line 3: Each time the Loop execute the message and show
  4. Line 4: Counter increment the value of 1 each time the loop execute
  5. Line 5: End of the While End While Loop body

A while loop can be terminated when a break, goto, return, or throw statement transfers control outside the loop. To pass control to the next iteration without exiting the loop, use the continue statement.

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, 
	ByVal e As System.EventArgs) Handles Button1.Click
        Dim counter As Integer
        counter = 1
        While (counter <= 10)
            MsgBox("Counter Now is : "  counter)
            counter = counter + 1
        End While
    End Sub
End Class

When you execute the program 10 times the message shows with counter and exit from the While .. End While loop. (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About