Here are the four types of looping construct in Visual Basic.
For Loop example
Private Sub ForLoop()
Dim intX As Integer
'-->INCREMENTING
For intX = 0 To 10
MsgBox "For Loop #" & intX, vbInformation, _
"Visual Basic Looping"
Next
'-->DECREMENTING
For intX = 10 To 0 Step -1
MsgBox "For Loop Step -1 #" & intX, vbInformation, _
"Visual Basic Looping"
Next
End Sub
Do While Loop example
Private Sub DoWhileLoop()
Dim intX As Integer
intX = 0
Do While intX < 10
MsgBox "Do While Loop #" & intX, vbInformation, _
"Visual Basic Looping"
intX = intX + 1
Loop
End Sub
While Wend Loop example
Private Sub WhileWendLoop()
Dim intX As Integer
intX = 0
While intX < 10
MsgBox "While Wend Loop #" & intX, vbInformation, _
"Visual Basic Looping"
intX = intX + 1
Wend
End Sub
Do Loop Example
Private Sub DoLoop()
Dim intX As Integer
intX = 0
Do
MsgBox "Do Loop #" & intX, vbInformation, _
"Visual Basic Looping"
intX = intX + 1
Loop While intX < 10
End Sub
0 comments:
Post a Comment