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 if is just an else containing another if (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 float and the other is int, Luma promotes the int to float before evaluating.
  • Example: if score / 2 > 3.5 { ... } is valid even if score is int.
Last updated on