REPEAT

Top  Previous  Next

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

 

 

REPEAT
 statement;
UNTIL <expr>
END_REPEAT;

 

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

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  a   : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  a := 0; // Even if we assign 200 to 'a' at this point, the statements
          // between REPEAT and UNTIL will be executed once as the test
          // is done AFTER the first execution of the statements        !
  REPEAT
    a := a + 10;
  UNTIL a > 100
  END_REPEAT;
END;
 
END_PROGRAM;