Is there a method of exiting/breaking a while
in VBS/VBA?
Following code won\'t work as intended:
num = 0
while (num < 10)
if (s
Incredibly old question, but bearing in mind that the OP said he does not want to use Do While
and that none of the other solutions really work... Here's something that does exactly the same as a Exit Loop
:
This never runs anything if the status is already at "Fail"...
While (i < 20 And Not bShouldStop)
If (Status = "Fail") Then
bShouldStop = True
Else
i = i + 1
'
' Do Something
'
End If
Wend
Whereas this one always processes something first (and increment the loop variable) before deciding whether it should loop once more or not.
While (i < 20 And Not bShouldStop)
i = i + 1
'
' Do Something
'
If (Status = "Fail") Then
bShouldStop = True
End If
Wend
Ultimately, if the variable Status
is being modified inside the While
(and assuming you don't need i
outside the while, it makes no difference really, but just wanted to present multiple options...