For ... Next (statement)

<< Click to Display Table of Contents >>

For ... Next (statement)

For Counter = InitialValue To FinalValue [Step StepSize]

 [Statements]

 [Exit For]

 [Statements]

Next [Counter]

Executes a group of statements in a loop.

Counter is the counter variable that is increased by the value indicated in StepSize at each iteration.

InitialValue is the initial value for Counter.

FinalValue is the final value for Counter.

StepSize is the step value. If it is omitted, the step value is 1.

In the first iteration, Counter assumes the value of InitialValue. At each additional iteration, StepSize is added to the value of Counter. The loop execution will end as soon as FinalValue is exceeded.

See also: For Each Next, Exit, section Flow control

Example:

Sub Main

 Dim x, y, z

 For x = 1 To 3

         For y = 1 To 3

                 For z = 1 To 3

                         Print z, y, x

                 Next z

         Next y

 Next x

End Sub