you can exit a doloop using the exit do statement


You can exit a Do...Loop using the Exit Do statement. Since usually you desire to exit only in certain situations, such as to ignore an endless loop, you should employ the Exit Do statement in the True statement block of an If...Then...Else statement. If condition is False, the loop runs as usual. Or else, you probably did not require a loop in the first place.

In the following instance, myNum is assigned a value which creates an endless loop. The If...Then...Else statement verify for this condition, stop the endless repetition.

Sub ExitExample()

Dim counter, myNum counter = 0

myNum = 9

Do Until myNum = 10 myNum = myNum - 1 counter = counter + 1

If myNum < 10 Then Exit Do

Loop

MsgBox "The loop made " & counter & " repetitions." End Sub

Request for Solution File

Ask an Expert for Answer!!
Visual Basic Programming: you can exit a doloop using the exit do statement
Reference No:- TGS0265904

Expected delivery within 24 Hours