WHILE

Top  Previous  Next

WHILE statements are used for repetitive conditional execution of code in VPL programs.

 

WHILE <expr> DO
 statement;
END_WHILE;

 

<expr> is an expression that evaluates to a BOOL. As long as <expr> evaluates to TRUE, the code until END_WHILE will be executed repeatedly. The WHILE loop can be terminated by using the EXIT statement. Please note that unlike a REPEAT statement, the <expr> is evaluated before the code is executed, and if the <expr> is FALSE, the code between the WHILE and END_WHILE will not be executed.

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  a   : INT;
  str : STRING;
END_VAR;
 
PROGRAM test;
 
BEGIN
  a := 0;
  WHILE a < 10 DO
    a := a + 1;
  END_WHILE;
  // At this point a is 10
 
END;
 
END_PROGRAM;