The following code displays a message box saying "Do you want to beep some more?". When the user presses no the loop stops. This code uses both the above syntax's.
Syntax 1:
Dim Ans As Integer
Do Until Ans = vbNo
Beep ' Beep!
Ans = Msgbox ("Do you want to beep some more?",
vbYesNo)
Loop
---Or---
Syntax 2:
Dim Ans As Integer
Do
Beep ' Beep!
Ans = Msgbox ("Do you want to beep some more?", vbYesNo)
Loop Until Ans = vbNo
To Exit the loop you can use the statement Exit Do.
Dim Ans As Integer
Do
Beep ' Beep!
Ans = Msgbox ("Do you want to beep some more?", vbYesNo)
If Ans = vbNo Then Exit Do
Loop
Comments