Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Latest commit

 

History

History
36 lines (27 loc) · 731 Bytes

if...else.md

File metadata and controls

36 lines (27 loc) · 731 Bytes

if...else

The if...else conditional expression returns one of two values based on a condition. It looks like this:

if (condition) {
  value1
} else {
  value2
}

There are some rules that will be enforced:

  • The else branch must be present, if it's missing you will get a syntax error. This ensures you handle all possibilities.
  • The condition must evaluate to type Bool.
  • The values of both branches must evaluate to the same type

{% hint style="info" %} Currently there is no shorthand for a conditional expression. {% endhint %}

else if ...

Multiple if..else statements can be written in sequence:

if (number > 5) {
  true
} else if (number > 2 {
  true
} else {
  false
}