Skip to main content

15.4.16 Operators

15.4.16.1 Basic operators

15.4.16.1.1 Arithmetic operators

Arithmetic operators include:

Operators

Application

+

Plus

-

Minus

*

Multiply

/

Divide

%

Modular arithmetic

 — 

Decrement

++

Increment

Arithmetic operators support data types of bool, byte, int, and double, and if different types of variables are added, subtracted, multiplied, and divided, they will trigger implicit conversion.

The examples for arithmetic operators are as follows:

Example 1

VAR int a = 1;
VAR int b = 2;
VAR int c = -b;//Negate
VAR int ac = a  *  c; //Multiplication

Example 2 The two operators ++ and --, also known as unary operators, are operators that operate on an operand. RL does not distinguish between pre and post increment or decrement:

x = n{plus}{plus}; //Means to add n by 1 and assign the n value to x
x = --n; //Means to subtract n by 1 and assign the new value to x

Example 3

Implicit conversion results of addition, subtraction, multiplication, and division of different types of variables:

Type 1

Type 2

Result

bool

bool

bool

bool

byte

byte

bool

int

int

bool

double

double

byte

byte

byte

byte

int

int

byte

double

double

int

int

int

int

double

double

double

double

double

15.4.16.1.2 Logical operators

Logical operators support the operation of the basic data types, including

Operators

Application

&&

Logical conjunction

||

Logical disjunction

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

==

Equal to

!=

Not equal to

!

Take logical negation

Logic and && expressions are true if the results on both sides are true, and the logic or || expression is true if one of the conditions of the two sides is true.

Example 1

The examples for other logical operators are as follows:

VAR int res = 1;
while(res  <  3) //Compare to determine whether res is less than 3
    res{plus}{plus};
endwhile
di5 = !di6; //Take logical negation
VAR int counter = 4;
while(di7&&di8) //Calculate logical conjunction
    if(counter == 5) //Whether it equals to
        break;
    endif
endwhile

15.4.16.1.3 Assignment operators

Assignment operators include:

Operators

Application

=

Assignment

+=

Addition assignment

-=

Subtraction assignment

*=

Multiplication assignment

/=

Division assignment

%=

Modulus assignment

The examples for assignment operators are as follows

VAR int num1 = 3;
VAR int num2 = 4;
num1 {plus}= num2; //Equivalent to num1 = num1 {plus} num2, then num1 = 7.
num1 -= num2; //Equivalent to num1 = num1 – num2, then num1 = -1.
num1  * = num2; //Equivalent to num1 = num1  *  num2, then num1 = 12.
num1 /= num2; //Equivalent to num1 = num1 / num2, then num1 = 0.
num1 %= num2; //Equivalent to num1 = num1 % num2, then num1 = 3.

All assignment operations of variables support implicit conversion. When the data types on the left and right sides of the assignment operation are inconsistent, the interpreter will attempt to trigger an implicit conversion to enable the program to continue running. When the conversion fails, the program will report an error and stop.

Bool, Byte, Int, and Double can be converted to each other. IO and register variables are special forms of the above four variables, and if they are used for assignment operations, they can also trigger implicit conversions.

If the return value of the function belongs to the above four variables, it can also be used as the right value of the assignment operation for assignment calculation.

Example 1

int tmp_num = 10.5; // 10
bool tmp_bool = 1; // true
tmp_bool = 0; // false
double tmp_d = 999; // 999.0

Example 2

  // Register variables can be directly used to modify ordinary variables
double tmp_num = register0;
  // Register variables can be directly used for conditional judgment
WaitUntil(register0 == 10);

Example 3

int mem_ret = StrMemb(“Robotics”, 2, “aeiou”);
  // The return value of StrMember is of type bool. If it is necessary to use an int type to receive the return value,
  // The controller will not report an error but will perform an implicit conversion
  // true -> 1 , false-> 0

15.4.16.1.4 Other operators

Operators

Application

()

Parentheses

.

Dot operator

The examples for the operators are as follows:

Example 1

VAR int num = arr; //Assign the first element of the array to num
VAR int num2 = (1{plus}2)*3; //Using parentheses can change the order of operations, the value of num2 here is 9

Example 2

Define a robtarget variable pt1
pt1.trans.x = 200; // Change the x coordinate of the pt1 point to 200 using the "." operator

Use restrictions:

The "." operator does not support modifications to the A, B, C members of robtarget variables.

15.4.16.2 Operation priority

Priority

Operators

Use form

Combination direction

1

( )

(Expression)/function name (formal parameter list)

.

Variable name.

2

-

-Expression

From right to left

++

++ Variable name/Variable name ++

 — 

--Variable name/Variable name — 

!

!Expression

3

/

Expression / Expression

From left to right

*

Expression * Expression

%

Integer expression / Integer expression

4

+

Expression + Expression

From left to right

-

Expression - Expression

5

>

Expression > Expression

From left to right

>=

Expression >= Expression

<

Expression < Expression

<=

Expression <= Expression

6

==

Expression == Expression

From left to right

!=

Expression != Expression

7

&&

Expression && Expression

From left to right

8

||

Expression || Expression

From left to right

9

=

Variable = Expression

From right to left

/=

Variable /= Expression

*=

Variable *= Expression

%=

Variable % = Expression

+=

Variable += Expression

-=

Variable -= Expression