20 lines
536 B
Text
20 lines
536 B
Text
|
|
int i = 19
|
|||
|
|
^|if–then–else|^
|
|||
|
|
if i > 18
|
|||
|
|
writeLine("greater than 18")
|
|||
|
|
else
|
|||
|
|
writeLine("less or equal to 18")
|
|||
|
|
end
|
|||
|
|
^|else if|^
|
|||
|
|
if i == 18 do writeLine("equal to 18")
|
|||
|
|
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|^
|
|||
|
|
Map dispatch = int%fun[
|
|||
|
|
18 => <|writeLine("equal to 18"),
|
|||
|
|
19 => <|writeLine("yeah, it's 19")]
|
|||
|
|
if dispatch.has(i) do dispatch[i]() end
|