# Keyword Reference

# For...To...Step...Next

Loop based on an expression.

For <variable> = <start> To <stop> [Step <stepval>]
statements
...
Next

## Parameters

variable | The variable used for the count.
start | The initial numeric value of the variable.
stop | The final numeric value of the variable.
stepval | [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1.

## Remarks

The variable will be created automatically with Local scope, even when MustDeclareVars is on.
For...Next statements may be nested. The For loop terminates when the value of variable exceeds the stop threshold. If stepVal or stop is a variable, its value is only read the first time the loop executes.
A For loop will execute zero times if:
start > stop and step > 0, or
start < stop and step is negative

## Related

ContinueLoop, ExitLoop

## Example

    #include <MsgBoxConstants.au3>

    For $i = 5 To 1 Step -1
        MsgBox($MB_SYSTEMMODAL, "", "Count down!" & @CRLF & $i)
    Next
    MsgBox($MB_SYSTEMMODAL, "", "Blast Off!")