ifelse - Help

# Online Help

###### All Products    Maple    MapleSim

Home : Support : Online Help : ifelse

ifelse

the conditional function

 Calling Sequence Conditional Function ifelse(conditional expression, true expression, false expression) if(conditional expression, true expression, false expression)

Description

 • The ifelse(c,a,b) function requires three arguments and returns the evaluation of the second or third, depending on the truth value of the first.
 • The first argument a must be a conditional expression; if it evaluates to true, b is evaluated and returned.  If a evaluates to false or FAIL, then c is evaluated and returned.
 The name if is an alias for ifelse. When using this name, if must be enclosed in back quotes (left single quotes) because if is a Maple reserved word.

Conditional Expressions

 • A conditional expression is any Boolean expression formed using the relational operators ( <, <=, >, >=, =, <> ), the logical operators (and, or, not), and the logical names (true, false, FAIL).
 • When a conditional expression is evaluated in this context, it must evaluate to true, false, or FAIL; otherwise, an error occurs.

Thread Safety

 • The ifelse function is thread-safe as of Maple 15.
 • For more information on thread safety, see index/threadsafe.

Examples

Simple Case

 The conditional operator can be used inside an equation. Since b (3) is not less than a (5), the result of the inner if command will be the false expression, b, which is used as part of the calculation.
 > $5\left(\mathrm{π}+\mathrm{ifelse}\left(b
 ${5}{}{\mathrm{π}}{+}{5}{}{\mathrm{if}}{}\left({b}{<}{a}{,}{a}{,}{b}\right)$ (1)

Using  ifelse with NULL

 Since a is less than b, x is assigned NULL. Unlike every other function call, which removes NULLs from the calling sequence, NULL can be used with the if operator.
 > $x≔\mathrm{ifelse}\left(a
 ${x}{≔}{\mathrm{if}}{}\left({a}{<}{b}{,}{\mathrm{NULL}}{,}{b}\right)$ (2)

 See Also