For-Next

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
  Next

Example 2

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

Example 3

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

Example 4

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