
- VBScript Tutorial
- VBScript - Home
- VBScript - Overview
- VBScript - Syntax
- VBScript - Enabling
- VBScript - Placement
- VBScript - Variables
- VBScript - Constants
- VBScript - Operators
- VBScript - Decisions
- VBScript - Loops
- VBScript - Events
- VBScript - Cookies
- VBScript - Numbers
- VBScript - Strings
- VBScript - Arrays
- VBScript - Date
- VBScript Advanced
- VBScript - Procedures
- VBScript - Dialog Boxes
- VBScript - Object Oriented
- VBScript - Reg Expressions
- VBScript - Error Handling
- VBScript - Misc Statements
- VBScript Useful Resources
- VBScript - Questions and Answers
- VBScript - Quick Guide
- VBScript - Useful Resources
- VBScript - Discussion
VBScript Exit For statement
A Exit For Statement is used when we want to Exit the For Loop based on certain criteria. When Exit For is executed, the control jumps to next statement immediately after the For Loop.
Syntax
The syntax for Exit For Statement in VBScript is −
Exit For
Flow Diagram

Example
The below example uses Exit For. If the value of the Counter reaches 4, the For 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"> Dim a : a = 10 For i = 0 to a Step 2 'i is the counter variable and it is incremented by 2 document.write("The value is i is : " & i) document.write("<br></br>") If i = 4 Then i = i*10 'This is executed only if i = 4 document.write("The value is i is : " & i) Exit For 'Exited when i = 4 End If Next </script> </body> </html>
When the above code is executed, it prints the following output in the console.
The value is i is : 0 The value is i is : 2 The value is i is : 4 The value is i is : 40
vbscript_loops.htm
Advertisements