Loop with counter, automatically increments or decrements. The loop will be entered if the loop counter can can reach the target value and will leave the loop when the target count value is passed. Calculation and comparison of the loop target value is executeted at the loop beginning. Syntax:

The keyword to increments the loop counter, downto decrements it.
The optional keyword step defines the step of a loop cycle. A positive constant is expected. Default is 1.

See also: Continue

Example 1

  dim i as byte
  For i=1 to 10
    Print "Hello"  ' Print "Hello" 10 times

Example 2

  dim i as byte
  For i=10 downto 1  ' Loop counter downwards
    Print "Hello"  ' Print "Hello" 10 times

Example 3

  dim i,a,b as byte
  For i=a to a+b
    Print "Hello"  ' Print "Hello" 11 times

Example 4

  dim i,a as byte
  For i=1 to a     ' Lopp will be omitted because the the loop counter can not reach the target value
    Print "Hello"
1) step as of 3875