IF

Top  Previous  Next

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

 

 

IF <expr> THEN
  statement;
ELSIF <expr> THEN
  statement;
ELSE
  statement;
END_IF;

 

<expr> is an expression that evaluates to a BOOL, and it is therefore always either TRUE or FALSE. Based on the <expr>, the code after the THEN keyword is either executed or bypassed.

 

 

 

 

Example:

INCLUDE rtcu.inc
 
VAR
   a   : INT;
   b   : INT;
   str : STRING;
END_VAR;
 
PROGRAM test;
 
BEGIN
 
   IF a > b THEN
      str := "a is grater than b";
   ELSIF a = b THEN
      str := "a equals b";
   ELSE
      str := "a is lesser than b";
   END_IF;
 
END;
 
END_PROGRAM;