If / Else
Use if to conditionally execute code. Add else (and else if) to branch on alternative conditions. Conditions must evaluate to bool.
if <condition> {
// then-block
}
if <condition> {
// then-block
} else {
// else-block
}
if <cond1> {
// block A
} else if <cond2> {
// block B
} else {
// block C
}- Braces
{ ... }are required for blocks (even for a single statement). else ifis just anelsecontaining anotherif(parsed and compiled accordingly).
Conditions
Any expression that yields bool can be used as a condition. Common patterns:
- Comparisons:
==,!=,<,>,<=,>= - Logical ops:
&&,||,!(standard precedence applies) - Identifier truthiness is not supported - you must write explicit comparisons (e.g.,
count > 0).
Numeric comparisons & coercion
When comparing or combining numbers:
- If one side is
floatand the other isint, Luma promotes theinttofloatbefore evaluating. - Example:
if score / 2 > 3.5 { ... }is valid even ifscoreisint.
Last updated on