ifelse - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : ifelse

ifelse

the conditional function

 

Calling Sequence

Description

Conditional Expressions

Thread Safety

Examples

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

a3&semi;b5

a3

b5

(1)
  

The conditional operator can be used inside an equation. Since b (5) is not less than a (3), the result of the inner ifelse command will be the false expression, b, which is used as part of the calculation.

5π+ifelseb<a&comma;a&comma;b

5π+25

(2)

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 ifelse operator.

xifelsea<b&comma;NULL&comma;b

See Also

boolean

if