Do...Loop

First we're going to use the Do...Loop while construct to repeatedly execute a block of code until a certain condition is met. Take a look at this modification of our example script:

Dim Greeting
Dim UserName
Dim TryAgain
Do
TryAgain = "No"
UserName = "InputBox("Please enter your name:")
If Trim(UserName) = " " Then
MsgBox "You must enter your name."
TryAgain = "Yes"
Else
Greeting = "Hello. " & UserName & ", it's a pleasure to meet you."
End If
Loop While TryAgain = "Yes"
MsgBox Greeting

Notice the block of code that starts with the word Do and ends with the line that starts with the word Loop. The indentation should make this code block easy to identify. This is the definition of our loop. The code inside the loop will keep executing until at the end of the loop, the TryAgain variable equals "No".

First
Next