Operators
Arithmetic, comparison, and logical operators in Soplang, with examples and precedence rules.
Operators in Soplang
Soplang supports arithmetic, comparison, and logical operators.
Arithmetic Operators
Use these operators with integers (abn) and floating-point numbers (jajab).
| Operator | Meaning | Example |
|---|---|---|
+ | Addition | a + b |
- | Subtraction | a - b |
* | Multiplication | a * b |
/ | Division | a / b |
% | Modulo | a % b |
abn a = 10 abn b = 3 qor("Wadarta: " + (a + b)) qor("Hadhaaga: " + (a % b))
Comparison Operators
Comparison operators test equality and ordering between values.
| Operator | Meaning | Example |
|---|---|---|
== | Equal | a == b |
!= | Not equal | a != b |
> | Greater than | a > b |
< | Less than | a < b |
>= | Greater or equal | a >= b |
<= | Less or equal | a <= b |
door a = 5 door b = 10 qor("a == b: " + (a == b)) qor("a < b: " + (a < b))
Logical Operators
Logical operators combine or negate boolean conditions.
| Operator | Meaning | Example |
|---|---|---|
&& | Logical AND | (a > 5) && (b < 10) |
|| | Logical OR | (a < 5) || (b > 3) |
! | Logical NOT | !(a == b) |
abn x = 5 abn y = 10 bool isInRange = (x > 3) && (y < 15) bool isMismatch = !(x == y) qor("Is in range: " + isInRange) qor("Mismatch: " + isMismatch)
Operator Precedence
Operators have the following precedence, from highest to lowest:
- Unary:
!,- *,/,%+,-- Comparison:
==,!=,>,<,>=,<= - Logical:
&&,||
&& and || have equal precedence
Many languages give && higher precedence than ||. In Soplang, both have equal precedence and group from left to right: run || been && been evaluates to been. Use parentheses when combining them, such as run || (been && been).
String Concatenation
+ also joins strings. When either operand is a string, the other value, such as a number, boolean, or list, is converted to text.
qor("Soplang " + "waa fiican") // Soplang waa fiican qor("Da'da: " + 25) // Da'da: 25 // Store the result of a comparison door natiijo = 5 > 3 qor(natiijo) // run
Division (/) can produce a fractional result: 10 / 4 is 2.5. Division by zero (x / 0) produces a runtime error.