Why We Added The Loop Counter?

Function GetUserName
'Prompts the user for his name. If the user refuses to provide
''his name five times, we give up and return a zero-length string.
Dim UserName
Dim TryAgain
Dim LoopCount
LoopCount = 1
Do
TryAgain = "No"
UserName = InputBox("Please enter your name:")
UserName = Trim(UserNAme)
If UserName = " " Then
If LoopCount > 5 Then
UserName = " "
TryAgain = "No"
Else
MsgBox "You must enter your name."
TryAgain = "Yes"
End If
LoopCount = LoopCount + 1
Loop While TryAgain = "Yes"
GetUserNAme = UserNAme
End Function

The reason we added the loop counter to the code is that our goal is to create a perfect black box. A perfect black box is very predictable as possible. The more predicable it is, the less the code that calls the procedure has to worry about it. If the user is being difficult and does not want to enter his name, we don't want to keep looping around forever., asking again and again. So after asking five times, the function gives up and returns a zero-length string.

First
Next