#### Revision [16566]

This is an old revision of KeyPgIif made by FxMwikki on 2013-02-01 09:08:29.

### IIF

Conditional function that returns one of two values.

**Syntax:**

`
`

**IIf**(

*condition*,

*expr_if_true*,

*expr_if_false*)

**Parameters:**

*condition*
The condition to test.

A non-zero value evaluates as true, while a value of zero evaluates as false.

A non-zero value evaluates as true, while a value of zero evaluates as false.

*expr_if_true*
An expression to evaluate and return if

It must return:

`is true.`*condition*It must return:

- a numeric value, which can be an integer, floating point number or a pointer,
- or a string value,
- or an UDT value.

*expr_if_false*
An expression to evaluate and return if

It must be same type as

`is false.`*condition*It must be same type as

`(either numeric, either string or UDT).`*expr_if_true***Description:**

`returns a different numeric or string or UDT value depending of the result of a conditional expression. Its typical use is in the middle of an expression; it avoids splitting it to put a conditional in the middle.`

**IIf**`only evaluates the expression that it needs to return. This saves time, and can also be useful to prevent evaluating expressions that might be invalid depending on the`

**IIf**`.`

*condition***Warning:**The capacity to accept different numeric types to be mixed, strings and UDTs is only supported from the fbc version 0.25.

**Examples:**

Dim As Integer a, b, x, y, z

a = (x + y + IIf(b > 0, 4, 7)) \ z

is equivalent to:a = (x + y + IIf(b > 0, 4, 7)) \ z

Dim As Integer a, b, x, y, z, temp

If b > 0 Then temp = 4 Else temp = 7

a = (x + y + temp) \ z

If b > 0 Then temp = 4 Else temp = 7

a = (x + y + temp) \ z

Dim As Integer I

I = -10

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

I = 0

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

I = 10

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

Sleep

I = -10

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

I = 0

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

I = 10

Print I, IIf(I>0, "positive", IIf(I=0, "null", "negative"))

Sleep

**Dialect Differences:**

- Not available in the
*CompilerOptlang -lang qb*dialect unless referenced with the alias.**__Iif**

**Differences from QB:**

- New to FreeBASIC

**See also:**

Back to Miscellaneous