Learn to program in Visual Basic .NET, the right way

Loops - For/Next

What is a For/Next Loop?

A For/Next loop allows you to repeat an action a specified number of times.

Iteration

A For/Next loop starts a specified number and will stop repeating once the number has incremented to another specified number.

The following demonstrates how to implement a For/Next loop:

Fiddle: Live Demo

Step

By default, a For/Next loop will increment by one. If you wanted to specify the increment of the loop, then you would append the Step to the loop:

The following demonstrates how to implement a backwards For/Next loop:

Fiddle: Live Demo

Remarks

In both of the examples provided, the numeric increment value was an Integer. However, the type is not restricted to just an Integer; the type could be a Double or any numeric data type.

The same applies to the Step.