Vbscript Exit For Loop To Break
Vbscript Exit For is used to break the iterative sequence of for loop counter. Generally Exit For keyword of vbscript is placed inside if then condition block that tests the value of counter variable or any other parameter evaluated using for loop counter variable. When vbscript if condition returns true then exit for statement gets executed just after the code lines placed inside if then condition block. Vbscript Exit For keyword terminates the for loop iterations before its complete execution.
Classic ASP VbScript Array Functions Examples:
You can see the live samples and examples of Classic ASP VbScript Array Functions from the following links:
Syntax of Vbscript Exit For Loop To Break
For variableName = 0 To 10 'code lines here If [condition] then 'code lines here Exit For End If Next
In the above syntax you can see that Exit For is coded inside the if then condition. When if condition returns true and passes the test then code block inside the if condition block gets executed and Exit For code statement breaks the repeating code execution sequence of for loop iterations.
Example of Vbscript Exit For Loop To Break
<% Dim myArray(11) myArray(0) = "January" myArray(1) = "February" myArray(2) = "March" myArray(3) = "April" myArray(4) = "May" myArray(5) = "June" myArray(6) = "July" myArray(7) = "August" myArray(8) = "September" myArray(9) = "October" myArray(10) = "November" myArray(11) = "December" Dim counter For counter = 0 To UBound(myArray) Response.Write(myArray(counter) & "<br />") If counter = 5 Then Exit For End If Next Response.Write("<br />") Response.Write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />") Response.Write("<br />") For counter = UBound(myArray) To 0 step -1 Response.Write(myArray(counter) & "<br />") If counter = 6 Then Exit For End If Next %>
Continue to next tutorial: Vbscript Add to Array using For Loop to learn how increase the length of an Array and add items dynamically using for loop.