The assignment operator is one equal sign:
int x = 5;
arr[5] = arr[5] + 1;
A compound assignment expression compose assignment and operation in one structure.
The next compound assignment operators exist: +=, -=, /=, *=, &=, |=, ^=.
For example:
int n = 10;
n += 5; // equal to n = n + 5; in result n = 15
int x = 5;
x &= 1; // equal to x = x & 1; in result x = 0
Arithmetic Operators
Symbol | Description | Usage Example |
+ | addition | int sum; sum = 4 + 8; |
– | subtraction | double difference; difference = 21.55 - 4.48; |
* | multiplication | double product; product = 3 * 6.5; |
/ | division | int quotient; quotient = 20 / 6; |
Comparison Operators
Symbol | Description | Usage Example |
< | is less than | (1 < 3); // true |
> | is greater than | (1 > 3); // false |
== | is equal to | (5 == 10); // false |
<= | is less than or equal to | (25 <= 24); // false |
>= | is greater than or equal to | (25 >= 24); // true |
<> | is not equal to | (10 <> 10); // false |
Note: The next construction is not correct:
bool result = (1 < 3);
int sum = 15 + 24;
Because result is latent constant and initialize on compilation, but expression (1 < 3) or 15+24 is evaluated on runtime. The right way is next:
bool result; result = (1 < 3);
int sum; sum = 15 + 24;
Operands must have digital types. Also, the operators == and <> can compare string and boolean value, but other operators can't compare string value.
Compare of double datatype
The operation == and <> are not available for double data type. If you need in comparison two double value, you should use variable Epsilon from package system and next construction:
if( (price1 - price2) > Epsilon )
// price1 not equal to price2
else
// price1 equal toprice2
About If-Else statement see at section Statements.
Logical Operators
Symbol
Description
Usage Example
&, and
and
while( (i < MAPeriod) and (i < count) )
{
sum+=Array[arrayNumber][i];
i+=1;
};
|, or
or
string res;
if( (a < k) or (a > k) )
{
res = IntToString(a) + " is out of the permissible range.";
};!, not
not
if( not (a == 0) )
{
c = b/a;
};
Bitwise Operators
Note: Bitwise operators are available only for integer numerics.
Symbol | Description | Usage Example |
~, not | Logic 'not' | int a = 4; // 410 = 1002 |
&, and | Bitwise 'and' | int a = 4; // 410 = 1002 |
|, or | Bitwise 'or' | int a = 4; // 410 = 1002 int c; c = a&b; // c = 410 |
^, xor | Bitwise 'xor' | int a = 4; // 410 = 1002 |
Comments