Operators & Expressions
Operators in Kyna allow you to combine, calculate, compare, and transform values.
Arithmetic Operators
| Operator | Name | Example | Result |
|---|---|---|---|
+ | Addition | 10 + 5 | 15 |
- | Subtraction | 10 - 5 | 5 |
* | Multiplication | 10 * 5 | 50 |
/ | Division | 10 / 2 | 5 |
% | Modulo (Remainder) | 10 % 3 | 1 |
const subtotal = 100;
const tax = subtotal * 0.08;
const total = subtotal + tax;
print("Total:", total); # 108.0
String Concatenation
Use + to concatenate strings and scalars:
const service = "auth";
const version = 1;
const path = "/api/v" + version + "/" + service;
print(path); # "/api/v1/auth"
Comparison Operators
Comparison operators evaluate to a bool (true or false):
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | Equal to | 42 == 42 | true |
!= | Not equal to | 42 != 10 | true |
< | Less than | 5 < 10 | true |
<= | Less than or equal | 10 <= 10 | true |
> | Greater than | 15 > 20 | false |
>= | Greater than or equal | 20 >= 20 | true |
Logical Operators
| Operator | Name | Description |
|---|---|---|
&& | Logical AND | Returns true only if both operands are true |
|| | Logical OR | Returns true if at least one operand is true |
! | Logical NOT | Inverts the truth value of the operand |
fn isEligible(age: int, hasPass: bool): bool {
return age >= 18 && hasPass;
}
print(isEligible(20, true)); # true
print(isEligible(16, true)); # false