FOR

Top  Previous  Next

FOR statements are used for iteration of code in VPL programs. The code between the FOR and END_FOR will be executed a number of times.

 

FOR <variable>:=<n> TO <m> BY <k> DO
  statement;
END_FOR;

 

The <variable> above is assigned the value n, and the statement is then executed. <variable> will the be incremented by the value <k>, and if <variable> is lesser than <m>, the statement is executed again, and so on. If the BY <k> is omitted, the <variable> is incremented by 1 each time.

 

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  a : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
 
  FOR a := 1 TO 100 BY 10 DO
    // a will get the values 10,20,30,40,50,60,70,80,90,100
     ...
  END_FOR;
 
END;
 
END_PROGRAM;