FuncIf
FuncIf
FuncIf[ cond, a, b ] returns a if a condition is true and b if it is false.
Usages
FuncIf[ cond, a, b ]
FuncIf[ cond, a, b ] is the expression form of If ... Else ... End: it returns a if cond is True, and b if cond is False. Only the chosen expression is executed, so the other one may even be invalid.
| Example | in | out |
|---|---|---|
| The condition is true. | FuncIf[ 5 >> 3, a, b ] |
a |
| The condition is false. | FuncIf[ 3 >> 5, a, b ] |
b |
| Choose a text. | n := 4 |
r = Text[`even`] |
L[[2]] does not exist, but it is not executed. |
L := {7} |
r = 0 |
Details
- Undecided condition: if
condcannot be decided,FuncIfis left unevaluated:FuncIf[ x >> 3, a, b ]staysFuncIf[x >> 3, a, b]. UseStrictto choosebin that case:FuncIf[ Strict[x >> 3], a, b ]givesb.
Warning
Use comparisons that are evaluated directly, such as ==, >>, <<, >==, <== and <<>>. With >, <, >=, <= or <>, the condition is not evaluated and FuncIf is left unevaluated: FuncIf[ 3 > 5, a, b ] stays FuncIf[3 > 5, a, b].
See also: If, Strict, Greater, EqualsEval