2024-10-16 18:07:41 -07:00
|
|
|
|
int i ← 19
|
2023-07-01 11:58:00 -04:00
|
|
|
|
^|if–then–else|^
|
|
|
|
|
|
if i > 18
|
|
|
|
|
|
writeLine("greater than 18")
|
|
|
|
|
|
else
|
|
|
|
|
|
writeLine("less or equal to 18")
|
|
|
|
|
|
end
|
|
|
|
|
|
^|else if|^
|
2024-10-16 18:07:41 -07:00
|
|
|
|
if i æ 18 do writeLine("equal to 18")
|
2023-07-01 11:58:00 -04:00
|
|
|
|
else if i < 18 do writeLine("less than 18")
|
|
|
|
|
|
else do writeLine("greater than 18")
|
|
|
|
|
|
end
|
|
|
|
|
|
^|when expression: just like iif in Visual Basic|^
|
|
|
|
|
|
writeLine(when(i > 18, "greater than 18", "less or equal to 18"))
|
|
|
|
|
|
^|hash-based conditionals|^
|
2024-10-16 18:07:41 -07:00
|
|
|
|
Map dispatch ← int%fun[
|
|
|
|
|
|
18 ⇒ <|writeLine("equal to 18"),
|
|
|
|
|
|
19 ⇒ <|writeLine("yeah, it's 19")]
|
2023-07-01 11:58:00 -04:00
|
|
|
|
if dispatch.has(i) do dispatch[i]() end
|