Control Variable in Do...Loop Code

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

Do
TryAgain = "No"

Here we are initializing our "control" variable . We call it the "control" variable because this variable will ultimately control whether or not the loop loops around again. We want to initialize this variable to "No" so that, by default, the loop will not loop around again. Only if a certain something occurs inside the loop will we set TryAgain to "Yes". This is yet another strategy in our ever-vigilant desire to expect the unexpected.

First
Next