Skip to main content

Operators & Expressions

Operators in Kyna allow you to combine, calculate, compare, and transform values.


Arithmetic Operators​

OperatorNameExampleResult
+Addition10 + 515
-Subtraction10 - 55
*Multiplication10 * 550
/Division10 / 25
%Modulo (Remainder)10 % 31
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):

OperatorMeaningExampleResult
==Equal to42 == 42true
!=Not equal to42 != 10true
<Less than5 < 10true
<=Less than or equal10 <= 10true
>Greater than15 > 20false
>=Greater than or equal20 >= 20true

Logical Operators​

OperatorNameDescription
&&Logical ANDReturns true only if both operands are true
||Logical ORReturns true if at least one operand is true
!Logical NOTInverts 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