# IIf
{: .no_toc }

Returns one of two values, depending on the evaluation of an expression.

Syntax: **IIf(** *expr* **,** *truepart* **,** *falsepart* **)**

*expr*
: *required* Expression to evaluate.

*truepart*
: *required* Value or expression returned if *expr* is **True**.

*falsepart*
: *required* Value or expression returned if *expr* is **False**.

> [!IMPORTANT]
> **IIf** always evaluates both *truepart* and *falsepart*, even though it returns only one of them. Watch for side effects: if the unused branch would raise an error (for example, division by zero), the error still occurs. Use the short-circuiting [**If**](/tB/Modules/Interaction/If.md) function --- a twinBASIC addition --- to guard against errors in the unused branch.

### Common Errors

| Error | When |
|---|---|
| [13 (`&HD`)](/Reference/Run-time-Errors.md#13), *Type mismatch* | *expr* is a string that is not a **Boolean** or a number |

### Example

This example uses **IIf** to return the word "Large" if the amount is greater than 1000, and "Small" otherwise.

```tb check_build
Function CheckIt(TestMe As Integer) As String
    CheckIt = IIf(TestMe > 1000, "Large", "Small")
End Function
```

### See Also

- [If](/tB/Modules/Interaction/If.md) function
- [Choose](/tB/Modules/Interaction/Choose.md) function
- [Switch](/tB/Modules/Interaction/Switch.md) function
