Do in Do...Loop Code

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


This starts the loop. This tells the script engine that we are starting a block of code that will define a loop. The script engine will expect to find a Loop statement somewhere further down in the script. This is similar to the If...End If code block: the script engine expects the block to be defined with beginning and ending statements. I'll get more into this later but take a note the Do statement on a line all by itself means that the loop will execute at least once. Even if the Loop While statement at the end of the block does not result in a loop-around back to the Do line, the code inside this block is going to execute at least one time.