Excel VBA – Do While [condition] … Loop

https://stackoverflow.com/questions/32728334/do-while-loop-and-while-wend-loop-whats-the-difference

  1. It supports checking the condition before entering the loop
    Do While [condition] ... Loop
     (zero or more loop executions)
  2. It supports checking the condition after entering the loop
    Do ... Loop While [condition]
     (one or more loop executions)

 

Sub While_Loop()
   Dim LTotal As Integer
   LTotal = 1
   While LTotal < 5
      Debug.Print (LTotal)
      LTotal = LTotal + 1
   Wend

End Sub

Sub DoWhile_Loop()
   Dim LTotal As Integer
   LTotal = 1
   Do While LTotal < 5
      Debug.Print (LTotal)
      LTotal = LTotal + 1
   Loop
End Sub