Loops


For - Next

Looping for a given number of times. more details

Public Sub ForNext1() 
Dim icount As Integer
   For icount = 1 To 10
'do something
   Next icount
End Sub

For - Each

Looping through all elements in a collection. more details

Public Sub ForEach2() 
Dim arValues As Variant
Dim oItem As Variant
   arValues = Array(1,2,3,4,5)
   For Each oItem In arValues
'do something
   Next oItem
End Sub

Do - While

Looping while a condition is true. more details

Public Sub DoWhile3() 
Dim icount As Integer
   icount = 1
   Do While (icount < 5)
'do something
      icount = icount + 1
   Loop
End Sub

Do - Until

Looping until a condition is meet. more details

Public Sub DoUntil4() 
Dim icount As Integer
   icount = 1
   Do Until (icount = 5)
'do something
      icount = icount + 1
   Loop
End Sub

Do - Loop

Looping indefinitely. Must include an Exit Do statement. more details

Public Sub DoLoop5() 
Dim icount As Integer
   Do
      icount = icount + 1
      If (icount = 5) Then
         Exit Do
      End If
   Loop
End Sub

While - Wend

This statement is provided for backwards compatibility and should not be used. more details


© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext