Visual Basic 6 for loop


For I as Integer = 1 To 10 Step 1
    code to execute

Step is optional and Step 1 is the default. Step tells it how to count, so -1 would have it subtract 1 each time and Step 5 would have it add 5 each time thru the loop.

In case the loop need to be stopped, then the Exit For statement can be used, as in the below example;

Dim iIndex as integer

For I as Integer = 1 To 10 Step 1

Debug.Print  I     
iIndex = I * 10

If iIndex > 90 Then
    Exit For
End If


Here, instead of printing 1 to 10, it will stop at 9, since the condition told the process to stop when iIndex reaches 90.