Operators
There are many different types of Operators that you will use within your Statelake script code.
But what is an Operator?
An Operator is simply a special character, symbol, or keyword that allows the script compiler to perform mathematical or logical equations.
Arithmetic Operators
Arithmetic Operators work with numeric data types such as Float and Integer.
Numeric data types can be further manipulated and compared through the use of Relational Operators.
Operator | Operation | Operand | Result | Example |
---|---|---|---|---|
+ | Addition | Float, Integer | Float, Integer | 1 + 2.06 |
- | Subtraction | Float, Integer | Float, Integer | 4 - 3.76 |
* | Multiplication | Float, Integer | Float, Integer | 2.67 * 5 |
/ | Float Division | Float, Integer | Float | 4.5 / 3 |
div | Integer Division | Integer | Integer | 10 div 3 (result 3) |
mod | Remainder | Integer | Integer | 10 mod 3 (result 1) |
Assignment Operator
An Assignment Operator is used to set the value of a variable or parameter.
Operator | Operation | Operand | Result | Example |
---|---|---|---|---|
:= | Assignment | Any data type | Any data type | Value := 10; |
Boolean Operators
Boolean Operators are used within expressions to join multiple conditions. The result of the expression depends on the result of the conditions, and how they are joined.
An example of usage is within an If statement with multiple conditions. Each condition can be joined through the use of a Boolean Operator.
if (Value>10) and (MyVariable=True) returns a True result only if both conditions evaluate to True .
if (Value>10) or (MyVariable=True) returns a True result if only one of the conditions evaluate to True.
if not (Value>10) will result in the test being reversed, and will only evaluate to True if the variable Value is less than 10.
While hardly ever used in a daily situation, xor is widely used however in cryptography, error checking and fault tolerance. Xor compares two input bits and generates one output bit. Where these two bits are the same, then 0 is returned, and where they are not the same, a 1 is returned.
Operator | Operation | Operand | Result | Example |
---|---|---|---|---|
not | negation | Boolean | Boolean | if not (Value > 10) then |
and | conjunction | Boolean | Boolean | if (Value>10) and (x=y) then |
or | disjunction | Boolean | Boolean | if (Value>10) or (x=y) then |
xor | exclusive disjunction | Boolean | Boolean | if (Value>10) xor (x=y) then |
Relational Operators
Relational Operators are used to compare the relationship between two data entities, and can compare any data type such as numeric, character string or logical data. The result of the comparison will be either True ( 1 ) or False ( 0 ), and can be used to make a decision regarding program flow.
To compare differing data types using these operators, first convert one data type side so that both sides are the same data type.
When using the less than or greater than operators against String data types, the comparison is performed using alphabetical sorting - abc is less than ade.
Operator | Operation | Operand | Result | Example |
---|---|---|---|---|
= | Equal | Any Data Type | Boolean | if 'abc' = 'abc' then |
<> | Not Equal | Any Data Type | Boolean | if 3 <> 4 then |
< | Less Than | Any Data Type | Boolean | if X < Y then |
> | Greater Than | Any Data Type | Boolean | if 3 > 5 then |
<= | Less than or equal | Any Data Type | Boolean | if X <= Y then |
>= | Greater than or equal | Any Data Type | Boolean | if 5 >= 8 then |
String Operators
String Operators work with String data types and will add then together to join them into a single string.
Strings can be compared through the use of Relational Operators.
Operator | Operation | Operand | Result | Example |
---|---|---|---|---|
+ | Concatenation | String | String | Value := 'abc' + 'def'; |