Operators and concatenating strings
An operator is a symbol that tells the interpreter to perform specific mathematical or logical manipulations. HaasScript is rich in built-in operators and provides the following type of operators:
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Misc Operators
This section will explain the arithmetic and relational operators along with how to concatenate strings.
Arithmetic Operators
Following table shows all the arithmetic operators supported by HaasScript language. Assume variable A holds 9 and variable B holds 5 then:
Operator | Description | Example |
+ | Add | A + B = 14 |
– | Subtract | A – B = 4 |
* | Multiply | A * B = 45 |
/ | Divide | A / B = 1.8 |
% | Modulus | B % A = 4 |
^ | Exponent | A^2 = 81 |
– | Unary negation | -A = -9 |
Relational Operators
Following table shows all the relational operators supported by HaasScript language. Assume variable A holds 10 and variable B holds 20 then
Operator | Description | Example |
== | Checks if the values are equal or not, if yes then condition becomes true. | (A == B) is false |
~= or != | Checks if the values are equal or not, if not then condition becomes true. | (A != B) is true |
> | Checks if the value on left is greater than the value on right, if yes then condition becomes true. | (A > B) is false |
< | Checks if the value on left is less than the value on right, if yes then condition becomes true. | (A < B) is true |
>= | Checks if the value on left is greater than or equal to the value on right, if yes then condition becomes true. | (A >= B) is false |
<= | Checks if the value on left is less than or equal to the value on right, if yes then condition becomes true. | (A <= B) is true |
Logical Operators
Following table shows all the logical operators supported by HaasScript language. Assume variable A holds true and variable B holds false then
Operator | Description | Example |
and | Called the logical AND operator. If both operands are non-zero (or non-nil) then condition becomes true. | (A and B) is false |
or | Called the logical OR operator. If either of the two operands are non-zero (or non-nil) then the condition becomes true. | (A or B) is true |
not | Called the logical NOT operator. Used to reverse the logical state of its operand. If a condition is true then logical NOT operator will make it false. | (not A) is false |
Misc Operators
Miscellaneous operators supported by HaasScript include concatenation and length.
Operator | Description | Example |
.. | Concatenates two strings. | a..b where a is “Hello ” and b is “World”, will return “Hello World”. |
# | An unary operator that returns the length of a string or table. | #”Hello” will return 5 |