FOR

FOR V=S TO E

BEGINS A LOOP WITH THE VARIABLE V USED AS COUNTER FROM S TO E

  • Type: Command
  • Parameter: 0
  • Group: Structures

ACTION

The command "FOR V=S TO E" is the beginning of a group of statements, which ends with NEXT and which uses the variable V as a counter.

The first time, the counter V is initiated with starting value S (V is S).

When NEXT is executed, the counter V is incremented, and then the group of statements between FOR and NEXT is executed again only if V is less than or equal to value in E.

Otherwise, if V is greater than E, the execution jumps to the statement after NEXT.

SYNTAX: FOR V=S TO E

  • V = variable used as a counter
  • S = starting value
  • E = end value

USE

  • FOR is used associated to NEXT, to make a "loop", that is a group of statements to be executed a number of times. The number of times is defined by the starting and end values.

ERROR

  • If V is not a correct variable name
  • If S is not a correct expression
  • If E is not a correct expression

EXAMPLE

rem print the 10 first integer numbers

dim i

for i=1 to 10

print i

next i

SEE ALSO

TO

STEP

NEXT