Arithmetic and Comparison Operators
Arithmetic Operators
Operator | Description | Example |
---|---|---|
+ | Addition | Total := A + B; |
- | Subtraction | Delta := A - B; |
* | Multiplication | Product := A * 5; |
/ | Division | Average := Sum / Count; |
You can use parentheses to control order of operations, just like in math:
Result := (Value1 + Value2) * 3;
When dividing integers, results are truncated (rounded down). Use REAL types if decimal precision is needed.
Comparison Operators
Operator | Description | Example |
---|---|---|
= | Equal to | IF Mode = 1 THEN |
<> | Not equal to | IF State <> 0 THEN |
< | Less than | IF Temp < 100 THEN |
> | Greater than | IF Speed > Limit THEN |
<= | Less than or equal | IF Level <= 50 THEN |
>= | Greater or equal | IF Count >= Max THEN |
Examples
// Add two values and scale the result
Result := (Value1 + Value2) * 3;
// Trigger an alarm if temperature exceeds 100
IF Temperature > 100 THEN
Alarm := 1;
END_IF;
// Check if count is not zero
IF Counter <> 0 THEN
Status := 1;
END_IF;
// Divide with decimal result
FlowRate := Volume / Duration; // Use REAL type for precision