Conditional operators can be used to identify whether a specified condition is true or false.
else
See if.
if
If the predicate evaluates to true, then execute the consequent statement or statements. Otherwise, execute the alternate statement or statements. Null evaluates to false, so if the predicate is null, then the alternate statement or statements will be executed.
Used in the following format, where predicate
must be a Boolean, consequent
and alternate
may be any expression and consequent statements
and alternate statements
may be any set of statements:
if predicate then consequent [else alternate]
if predicate then {
consequent statements
}
[else
{
alternate statements
}]
if predicate then {
consequent statements
}
[else alternate]
then
in if
statements, it is optional. Examples
if false then “hi” else 3.7 # value: 3.7
if true then 1 else null # value: 1
if ((2 > 5) or (42 >= 21)) then{
“hi” }
else 3.7 # value: “hi”
if ((42 < 21) and (42 > 84)) then
{
someVariable = 12
“hi”}
else
{
someVariable = 24
3.7
} # value: 3.7, and someVariable is 24.
switch
Compares the test value to each case value in order. If the test value equals a case value, then the value of the result is the value of the switch expression. If no case value matches, the default code block is used. Uses the same comparison criteria as the equals operator.
Used in the following format, where test
, case result
and default
may be any expression:
switch test {case result}* default
The return value type is the same as a result
parameter or default
.
Examples
# value: 3.5
test="hello"
test.switch (
"hi", 1, # case="hi", result=1
2.7, "bye", # case=2.7, result="bye"
"hello", 3.5, # case="hello", result=3.5
null) # default=null
then
See if.