For … To … Step … Next
Top  Previous  Next

For counter = start To end [Step step]
[statements]
Next

Repeats a group of statements a specified number of times.

Parameters
 
counter  
 
Variable used as a loop counter.  
 
start  
 
Initial value of counter.  
 
end  
 
Final value of counter.  
 
step  
 
Amount counter is changed each time through the loop. If not specified, step defaults to one. For automatically defines to increment or to decrement counter depending on start and end.  
 
statements  
 
One or more statements between For and Next that are executed the specified number of times.  
 
Remarks

Once the loop starts and all statements in the loop have executed, step is added to counter. At this point, either the statements in the loop execute again (based on the same test that caused the loop to execute initially), or the loop is exited and execution continues with the statement following the Next statement.  
start, end and step can be any expression or variable of any type.  
You can nest For...Next loops by placing one For...Next loop within another.  
Unlike While, For evaluates end only once.  
Empty For is ignored and cannot be used for time delay.  

Example
 
For i = 0 To 25  
       print i  
Next  
 
The following loop decrements i because end less than start.  
 
For i = 0 To -25 Step 2.56  
       print i  
Next  
   
Nested For:  
 
For i = 0 To 5  
       For j = 0 To 5  
              print "i = ", i, " j = ", j  
       Next  
Next