With the Step keyword, you can increase or decrease the counter variable by the value you specify.

In the example below, the counter variable (i) is INCREASED by two, each time the loop repeats.

For i=2 To 10 Step 2
  some code
Next

To decrease the counter variable, you must use a negative Step value. You must specify an end value that is less than the start value.

In the example below, the counter variable (i) is DECREASED by two, each time the loop repeats.

For i=10 To 2 Step -2
  some code
Next

Exit a For...Next

You can exit a For...Next statement with the Exit For keyword.

For i=1 To 10
  If i=5 Then Exit For
  some code
Next



Practice Excercise Practice now