### Revision history for KeyPgIif

#### Revision [22582]

Last edited on 2019-02-26 08:59:41 by fxm [Suppressed reference to fbc version 0.90]##### Deletions:

**Warning:** The ability to accept mixed numeric types, strings and UDTs is only supported from the fbc version 0.90.

##### Additions:

{{fbdoc item="ret"}}

if ##//condition//## is non-zero, ##//expr_if_true//##, otherwise ##//expr_if_false//##

if ##//condition//## is non-zero, ##//expr_if_true//##, otherwise ##//expr_if_false//##

#### Revision [21894]

Edited on 2017-09-09 09:27:41 by fxm [Suppressed specific behavior description when condition is resolved at compile-time]##### Additions:

##**IIf**## returns a different numeric or string or UDT value (not a reference) depending of the result of a conditional expression evaluated at run-time. Its typical use is in the middle of an expression; it avoids splitting it to put a conditional in the middle.

When IIf treats expressions of mixed numeric types (conditional expression evaluated at run-time):

- if at least one expression is of floating-point type, the result type is the floating-point type (the bigger in case of two floating-point types),

- if the two expressions are of integer types, the result type is the bigger type of both (see [[ProPgDataConversion|Coercion and Conversion]] for the precise ranking of integer types).

When IIf treats expressions of mixed numeric types (conditional expression evaluated at run-time):

- if at least one expression is of floating-point type, the result type is the floating-point type (the bigger in case of two floating-point types),

- if the two expressions are of integer types, the result type is the bigger type of both (see [[ProPgDataConversion|Coercion and Conversion]] for the precise ranking of integer types).

##### Deletions:

In the particular case where the condition is resolved at compile-time, ##**IIf**## returns the original expression itself that satisfies the ##//condition//## (otherwise, it only returns an evaluation of the expression at run-time).

When IIf treats expressions of mixed numeric types:

- if the ##//condition//## is resolved at compile-time:

- the result type is that of the expression satisfying the ##//condition//##,

- if the ##//condition//## can only be solved at run-time:

- if at least one expression is of floating-point type, the result type is the floating-point type (the bigger in case of two floating-point types),

- if the two expressions are of integer types, the result type is the bigger type of both (see [[ProPgDataConversion|Coercion and Conversion]] for the precise ranking of integer types).

##### Additions:

##**IIf**## returns a different numeric or string or UDT value (not a reference) 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.

In the particular case where the condition is resolved at compile-time, ##**IIf**## returns the original expression itself that satisfies the ##//condition//## (otherwise, it only returns an evaluation of the expression at run-time).

In the particular case where the condition is resolved at compile-time, ##**IIf**## returns the original expression itself that satisfies the ##//condition//## (otherwise, it only returns an evaluation of the expression at run-time).

##### Deletions:

##### Additions:

- a numeric value, which can be an integer, floating point number or a pointer, including Boolean,

##### Deletions:

#### Revision [21823]

Edited on 2017-08-17 04:04:35 by fxm [Added the rules for the result type in case of expressions of mixed numeric types]##### Additions:

When IIf treats expressions of mixed numeric types:

- if the ##//condition//## is resolved at compile-time:

- the result type is that of the expression satisfying the ##//condition//##,

- if the ##//condition//## can only be solved at run-time:

- if at least one expression is of floating-point type, the result type is the floating-point type (the bigger in case of two floating-point types),

- if the two expressions are of integer types, the result type is the bigger type of both (see [[ProPgDataConversion|Coercion and Conversion]] for the precise ranking of integer types).

- if the ##//condition//## is resolved at compile-time:

- the result type is that of the expression satisfying the ##//condition//##,

- if the ##//condition//## can only be solved at run-time:

- if at least one expression is of floating-point type, the result type is the floating-point type (the bigger in case of two floating-point types),

- if the two expressions are of integer types, the result type is the bigger type of both (see [[ProPgDataConversion|Coercion and Conversion]] for the precise ranking of integer types).

##### Additions:

##### Additions:

- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Iif""**##.

- ##[[KeyPgIfthen|If...Then]]##

- ##[[KeyPgIfthen|If...Then]]##

##### Deletions:

- ##[[KeyPgIfthen If...Then]]##

#### Revision [16931]

Edited on 2013-08-31 19:09:02 by CountingPine [May as well abandon the reference to 0.25]##### Additions:

**Warning:** The ability to accept mixed numeric types, strings and UDTs is only supported from the fbc version 0.90.

##### Deletions:

#### Revision [16929]

Edited on 2013-08-31 14:44:53 by FxMwikki [the fbc version 0.25 is in preview for the version 0.90]##### Additions:

**Warning:** The capacity to accept different numeric types to be mixed, strings and UDTs is only supported from the fbc version 0.25 (version in preview for the version 0.90).

##### Deletions:

#### Revision [16568]

Edited on 2013-02-01 15:08:04 by FxMwikki [IIF now accepts different numeric types to be mixed, strings and UDTs]##### Additions:

u2 = Iif(0 , u10, u20)

##### Deletions:

#### Revision [16567]

Edited on 2013-02-01 15:05:58 by FxMwikki [IIF now accepts different numeric types to be mixed, strings and UDTs]##### Additions:

{{fbdoc item="filename" value="examples/manual/control/iif4.bas"}}%%(freebasic)

Type UDT1

Dim As Integer I1

End Type

Type UDT2 Extends UDT1

Dim As Integer I2

End Type

Dim As UDT1 u1, u10 = (1)

Dim As UDT2 u2, u20 = (2, 3)

u1 = Iif(0, u10, u20)

Print u1.I1

u1 = Iif(1, u10, u20)

Print u1.I1

u2 = Iif(0 ,u10, u20)

Print u2.I1; u2.I2

'u2 = Iif(1, u10, u20) ''Invalid assignment/conversion

Type UDT1

Dim As Integer I1

End Type

Type UDT2 Extends UDT1

Dim As Integer I2

End Type

Dim As UDT1 u1, u10 = (1)

Dim As UDT2 u2, u20 = (2, 3)

u1 = Iif(0, u10, u20)

Print u1.I1

u1 = Iif(1, u10, u20)

Print u1.I1

u2 = Iif(0 ,u10, u20)

Print u2.I1; u2.I2

'u2 = Iif(1, u10, u20) ''Invalid assignment/conversion

#### Revision [16566]

Edited on 2013-02-01 09:08:29 by FxMwikki [IIF now accepts different numeric types to be mixed, strings and UDTs]##### Additions:

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.

It must be same type as ##//expr_if_true//## (either numeric, either string or UDT).

##**IIf**## 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.

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

%%is equivalent to:

{{fbdoc item="filename" value="examples/manual/control/iif3.bas"}}%%(freebasic)

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

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

- or a string value,

- or an UDT value.

It must be same type as ##//expr_if_true//## (either numeric, either string or UDT).

##**IIf**## 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.

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

%%is equivalent to:

{{fbdoc item="filename" value="examples/manual/control/iif3.bas"}}%%(freebasic)

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

##### Deletions:

It must be the same type of number as ##//expr_if_true//##.

##**IIf**## returns a different numeric 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.

is equivalent to:

#### Revision [14356]

Edited on 2009-08-29 21:54:29 by CountingPine [Remove CamelCase links in "New to FreeBASIC"]##### Additions:

- New to ""FreeBASIC""