### Table of Contents

# If(condition, when_true, when_false)

Category: Logical function

## Description

This function evaluates *condition* and returns the *when_true* value if the condition is true, or *when_false* if not.

## Arguments

Argument | Type | Description |
---|---|---|

condition | Expression | This is an expression or "test" that evaluates to either TRUE or FALSE. |

when_true | Expression | If the condition evaluates to TRUE, this value is returned. |

when_false | Expression | If the condition evaluates to FALSE, this value is returned. |

**Return value type:** Text, Number, Boolean (the value types used for *when_true* and *when_false*)

## Remarks

To return a Boolean TRUE or FALSE value, use the True() and False() functions.

If() functions can be nested to provide decisions based on more than a single test, and return a value from more than just two choices. See examples below.

Both *when_true* and *when_false* values are always evaluated, even if only one of them is returned.

## Examples

if(2+2=4, "Yes it does", "No it doesn't") //Returns "Yes it does"

if("This" = "That", 1, 0) //Returns 0 (Returns a numeric zero.)

if(rem(4,2)=0,"Number is even","Number is odd") //Returns "Number is even" (Using a function in the condition.)

if({MyVal}+6=8,"Is 2","Is not 2") //Returns "Is not 2" (Where "MyVal" = 3, parameters are supported.)

### Nested if()s

Another "level" of logic can be introduced by using a nested if() for the outer if()'s TRUE and/or FALSE value(s). This becomes the equivalent of an "elseif" branch.

if( [Field1)>10, "More than 10", if( [Field1]>0, "More than 0, less than 10", "Less than 0" ) )

If [Field1] is greater than 10, the condition is evaluated to TRUE and the *when_true* value ("More than 10") is returned. However, if the condition is evaluated to FALSE, the *when_false* "value" is another if() test, which is evaluated. In this case, if [Field1] is greater than 0, "More than 0" is returned, otherwise "Less than 0" is.

Nested if()s can be used for the *condition*, the *when_true*, and/or the *when_false* values.