Operator: = (Equal)

Top  Previous  Next

The = operator compares two numbers or strings and returns TRUE if they are equal.

Care must be taken when used with floating-point numbers due to rounding errors, e.g. 1.1 + 2.2 <> 3.3.

 

The comparison is case-sensitive.

See example 2 below.

 

 


Example 1:

 

INCLUDE rtcu.inc
 
VAR
   a : INT; 
   b : INT;
   t : BOOL;
END_VAR;
 
PROGRAM test;
 
BEGIN
   ...
   IF a = b THEN
      // Will be executed if a equals b
      ...
   END_IF;
   ...
   t := b 10; // t is TRUE if b equals 10
   ...
END;
 
END_PROGRAM;

 

 

Example 2:

 

INCLUDE rtcu.inc
 
VAR
   a : STRING := "Peter";
   b : STRING := "Jack";
END_VAR;
 
PROGRAM test;
 
BEGIN
   ...
   IF a = b THEN
      // Will not be executed as "Peter" is not equal to "Jack"
      ...
   END_IF;
END;
 
END_PROGRAM;