Conditionals

Conditionals can be written using the if espression:

if condition {
  expr1
} else {
  expr2
}

The former is evaluated to expr1 whenever condition evaluates to true, and evaluates to expr2 when condition evaluates to false.

Warning It will emit a runtime error whenever condition evalutes to a value that is not a boolean.

Syntax sugar for nested if expressions is also available:

if condition1 {
  expr1
} else if condition2 {
  expr2
} else {
  expr3
}

if is an expression, meaning you can actually write code like

let max_num =
  if a >= b {
    a
  } else {
    b
  }