An Exit Do Statement is used when we want to Exit the Do Loops based on certain criteria. It can be used within both Do..While and Do..Until Loops.
When Exit Do is executed, the control jumps to next statement immediately after the Do Loop.
The syntax for Exit Do Statement in VBScript is −
The below example uses Exit Do. If the value of the Counter reaches 10, the Do Loop is Exited and control jumps to the next statement immediately after the For Loop.
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> i = 0 Do While i <= 100 If i > 10 Then Exit Do ' Loop Exits if i>10 End If document.write("The Value of i is : " &i) document.write("<br></br>") i = i + 2 Loop </script> </body> </html>
When the above code is executed, it prints the following output in the console.
The Value of i is : 0 The Value of i is : 2 The Value of i is : 4 The Value of i is : 6 The Value of i is : 8 The Value of i is : 10