Sunday, December 19, 2010

While ..End While

Previous Next


While .. End While Loop execute the code until it meets the specified condition.
Syntax:

While [condition]
[loop of the body]
End While



Condition : The condition set by the user
1. counter = 1
2. While (counter <= 10)
3. Message
4. counter = counter + 1
5. End While

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

Example

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<=6) MsgBox(“Now Counter Value is :” & counter) Counter=counter+1 End While End Sub End Class