Skip to content

When Else

Sxtanna edited this page Jul 9, 2020 · 1 revision

When/Else statements are equivalent to "if/else" in other languages.

Syntax

when ('boolean expression') {
  'passing expression'
} {else {
  'failing expression'
}}

  1. when
  • When statements begin with the when keyword.
  1. boolean expression
  • When statements evaluate whether the expression returns true or false.
  1. passing expression
  • When statements must contain a block of code to be executed in the case of the expression evaluating to true.
  1. else (optional)
  • When statements can optionally contain a second else branch to be evaluated.
  1. failing expression
  • The block of code to be executed in the case of the expression evaluating to false.

Examples

when (true) {
  push "This will always be printed"
}
when (1 != 1) {
  push "This will never be printed"
} else {
  push "This will always be printed"
}