# Directives

NEXT | End FOR Loop

## Format

NEXT [var]

Where:

var | Optional control variable to be incremented or decremented. This variable must match the current FOR variable.

## Description

When PxPlus encounters the NEXT directive, the current variable is incremented or decremented by the STEP value, and if the current value does not exceed the ending value, control is returned to the directive following the FOR.

The variable you use in the NEXT directive must match that of the currently active FOR. If no FOR is active or the variables do not match, PxPlus returns an Error #28: No corresponding FOR for NEXT.

The control variable can be omitted from the NEXT directive because the increment/decrement of the FOR var is assumed automatically; however, the NEXT var is useful for readability purposes, especially if it appears within a nested loop structure.

## See Also

FOR ... NEXT Loop While Incrementing

## Example

for I=1 to 10
print I,
next ! NEXT I, since I is current
->run
1 2 3 4 5 6 7 8 9 10