Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

If expressions

To branch programs, you can use if expressions:

if n == 0 {
  "zero"
} else {
  "not zero"
}

Unlike typescript, there's no concept of boolean casting: the tested value has to be a Bool. This prevents all the javascript quirks of complex implicit casting rule, and undesired false positives in typechecking.

You can nest if-else expressions using an else if syntax as well:

if n == 0 {
  "zero"
} else if n == 1 {
  "one"
} else {
  "not sure"
}

⚠️ NOTE: nested else-if sugar isn't implemented yet