STEP

(FOR V=S TO E) STEP T

DEFINES THE STEP OF A LOOP "FOR"

  • Type: Directive
  • Parameter: 1
  • Group: Structures

ACTION

The command "FOR V=S TO E STEP T" 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 increased by T, 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.

Remark: to start by a starting value greater than the end value, we use the value -1 as step.

Example: FOR V=10 TO 1 STEP -1

SYNTAX: FOR V=S TO E STEP T

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

USE

  • STEP is used associated to FOR, TO andNEXT, 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. The step between each time is defined by T.

ERROR

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

EXAMPLE

rem print the first odd integer numbers

dim i

for i=1 to 10 step 2

print i

next i

SEE ALSO

FOR

TO

NEXT