# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.11 Types - Extended | Up: 8 API Reference | 8.13 Data Type Conversion > | 9 Release Notes >>

## 8.12 Utilities

### 8.12.1 Routines

#### 8.12.1.1 iif

    include std/utils.e
    namespace utils
    public function iif(atom test, object ifTrue, object ifFalse)

Used to embed an 'if' test inside an expression. `iif` stands for inline if or immediate if.

##### Parameters:

1. `test` : an atom, the result of a boolean expression
2. `ifTrue` : an object, returned if `test` is non-zero
3. `ifFalse` : an object, returned if `test` is zero

##### Returns:

An object. Either `ifTrue` or `ifFalse` is returned depending on the value of `test`.

Warning Note:
You must take care when using this function because just like all other Euphoria routines, this does not do any lazy evaluation. All parameter expressions are evaluated before the function is called, thus, it cannot be used when one of the parameters could fail to evaluate correctly. For example, this is an improper use of the `iif` statement:

    first = iif(sequence(var), var[1], var)

The reason for this is that both `var[1]` and `var` will be evaluated. Therefore if `var` happens to be an atom, the `var[1]` statement will fail.
In situations like this, it is better to use the long style.

    if sequence(var) then
         first = var[1]
      else
         first = var
      end if

##### Example 1:

    msg = sprintf("%s: %s", {
        iif(ErrType = 'E', "Fatal error", "Warning"),
        errortext
    })

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.11 Types - Extended | Up: 8 API Reference | 8.13 Data Type Conversion > | 9 Release Notes >>