An Expression is a combination of Literals, Variables, and operators that evaluates to a single value. Expressions allow you to perform calculations, comparisons, and logical operations to produce new values.
Arithmetic expressions use Arithmetic Operators to perform mathematical calculations on numeric values. The expression evaluates to a single numeric result.
NEW INT x = 5 + 3 // Expression: 5 + 3, evaluates to 8
NEW INT y = 10 * 2 // Expression: 10 * 2, evaluates to 20
NEW INT z = 100 / 4 // Expression: 100 / 4, evaluates to 25
PRINTLN x // Displays "8"
PRINTLN y // Displays "20"
PRINTLN z // Displays "25"Comparison expressions use Comparison Operators to compare two values. The expression always evaluates to a Boolean result (True or False).
NEW BOOL x = 5 > 3 // Expression: 5 > 3, evaluates to TRUE
NEW BOOL y = 10 == 10 // Expression: 10 == 10, evaluates to TRUE
NEW BOOL z = 7 < 2 // Expression: 7 < 2, evaluates to FALSE
PRINTLN x // Displays "TRUE"
PRINTLN y // Displays "TRUE"
PRINTLN z // Displays "FALSE"Logical expressions use Logical Operators to combine Boolean values. The expression evaluates to a single Boolean result.
NEW BOOL x = TRUE && FALSE // Expression evaluates to FALSE
NEW BOOL y = TRUE || FALSE // Expression evaluates to TRUE
NEW BOOL z = ( 5 > 3 ) && ( 10 < 20 ) // Expression evaluates to TRUE
PRINTLN x // Displays "FALSE"
PRINTLN y // Displays "TRUE"
PRINTLN z // Displays "TRUE"String expressions use the Concatenate operator to combine multiple values into a single string. Any data type can be concatenated with strings.
NEW STR greeting = "Hello" .. " " .. "World" // Expression evaluates to "Hello World"
NEW STR message = "Value: " .. 42 // Expression evaluates to "Value: 42"
NEW STR status = "Active: " .. TRUE // Expression evaluates to "Active: TRUE"
PRINTLN greeting // Displays "Hello World"
PRINTLN message // Displays "Value: 42"
PRINTLN status // Displays "Active: TRUE"Expressions can combine multiple operators and values. Use Groups to control the order of evaluation.
NEW INT x = ( 5 + 3 ) * 2 // Expression: ( 5 + 3 ) * 2, evaluates to 16
NEW INT y = 10 + 5 * 2 // Expression: 10 + 5 * 2, evaluates to 20
PRINTLN x // Displays "16"
PRINTLN y // Displays "20"NEW INT age = 25
NEW BOOL hasLicense = TRUE
NEW BOOL canDrive = ( age >= 18 ) && hasLicense
PRINTLN canDrive // Displays "TRUE"NEW INT a = 10
NEW INT b = 5
NEW STR result = "Sum: " .. ( a + b ) .. ", Product: " .. ( a * b )
PRINTLN result // Displays "Sum: 15, Product: 50"NEW INT x = 5
NEW INT y = x + 10 // Expression: x + 10
NEW INT z = y * 2 // Expression: y * 2
PRINTLN z // Displays "30"NEW INT x = 5
NEW INT y = 3
PRINTLN x + y // Expression: x + y, displays "8"
PRINTLN x > y // Expression: x > y, displays "TRUE"NEW INT score = 85
IF score >= 90 // Expression: score >= 90
PRINTLN "Grade: A"
ELIF score >= 80 // Expression: score >= 80
PRINTLN "Grade: B"
END IFNEW INT i = 1
WHILE i <= 5 // Expression: i <= 5
PRINTLN i
SET i = i + 1 // Expression: i + 1
END WHILENEW INT x = 5
NEW FLOAT y = 2.5
NEW INT z = x + y // Type error! Cannot mix Integer and Float in expressionNEW STR x = "Hello"
NEW STR y = "World"
PRINTLN x + y // Type error! Use the Concatenate operator (..) for strings
PRINTLN x .. y // Correct! Displays "HelloWorld"NEW INT x = 5
NEW STR y = "5"
NEW BOOL result = x == y // Type error! Cannot compare Integer and StringNEW BOOL x = TRUE
NEW INT y = 5
NEW INT z = x + y // Type error! Cannot use Boolean in arithmetic expression