For variable=x To y [Step z] [statement(s) [Next [variable]]]

For variable=x To y [Step z]


[Exit For]


Next [variable]

Executes a series of instructions a specified number of times in a loop.

  • variable is used as a counter

  • <x>, <y>, and <z> are numeric expressions

  • Step <z> specifies the counter increment for each loop.

If Step is not specified, the increment is assumed to be 1.

The first numeric expression <x> is the initial value of the counter.

The second numeric expression <y> is the final value of the counter.

Program lines following the For statement are executed until the Next statement is encountered.

Then, the counter is incremented by the amount specified by Step.

Exit For - Causes program execution to jump to the first statement following the Next statement.


Rem Prints first 10 positive integer numbers

For n%=1 To 10 : Print n%; “ “; : Next


1 2 3 4 5 6 7 8 9 10