For...Next

Last Modified: 1/3/2021

Creates a loop that repeats for the range specified or the Exit command is used.

Arguments

NameTypeRequiredDescription
CounterVariable Integer/Long Yes This variable gets updated after each loop iteration.
StartValue Integer/Long Yes This is the value that the loop begins with.
EndValue Integer/Long Yes This is the value that the loop ends at.
StepValue Integer/Long No How much to increment the CounterVariable by. If omitted, the compiler defaults the Step counter to 1.

Example

Syntax:
 
  For <CounterVariable> = <StartValue> To <EndValue> [Step <StepValue>]
    [Statements]
    [Continue]
    [Statements]
  Next
    For x = 1 To 10
        Print x
    Next

Remarks

If you need to create an indefinite loop, or a loop that terminates on a condition, consider using a Do...Loop loop or a While...Wend loop.

See Also

Do...Loop, Continue, Exit, While...Wend