VBScript For Loops


A for loop is a repetition control structure that allows a developer to efficiently write a loop that needs to execute a specific number of times.


The syntax of a for loop in VBScript is:

For counter = start To end [Step stepcount]
  [statement 1]
  [statement 2]
  [statement n]
  [Exit For]
  [statement 11]
  [statement 22]
  [statement n]

Flow Diagram

VBScript For Loops

Here is the flow of control in a For Loop:

  • The For step is executed first. This step allows you to initialize any loop control variables and increment the step counter variable.


  • After the body of the for loop executes, the flow of control jumps to the Next statement. This statement allows you to update any loop control variables. It is updated based on the step counter value.



<!DOCTYPE html>

   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)


The value is i is : 0

The value is i is : 2

The value is i is : 4

The value is i is : 6

The value is i is : 8

The value is i is : 10