The VBScript Network and Systems Administrator's Cafe

Jun 28 2008   11:20PM GMT

VBScript Statements: Explanation of the For … Next Statement



Posted by: Jerry Lees
for next, next, for, Conditional statements, VBScript, VBScript Statements, vbscriptstatements, step

The For Next statement is very useful for situations where you need to loop through a piece of code a specific number of times. 
 
You can use Exit For statements to exit out of a For loop, if you need to check for a condition inside the loop. Additionally, The Step keyword at the end of the line that has the for statement will allow you to loop through a For statement in any size of increment. 

Here is an example of a for statement, followed by one with a Step key word:

For x = 1 to 10
     wscript.echo x
next

For x=1 to 20 step 2
    wscript.echo x
next

 

Comment on this Post


You must be logged-in to post a comment. Log-in/Register