| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Returns the result of an expression based on a logical expression
If( <lCondition>, <exprTrue>, <exprFalse> ) --> xValue or IIf(<lCondition>, <exprTrue>, <exprFalse> ) --> xValue
The function returns the value of <exprTrue> if <lCondition> is .T. (true), otherwise the value of <exprFalse> is returned.
Function If(), and its syntactical synonym IIf(), is a conditional function providing two possible return values. It first evluates the expression <lCondition>. Based on this result, it returns the value of either <exprTrue> or <exprFalse>.
| See also: | DO CASE, IF, SWITCH |
| Category: | Conversion functions , Logical functions |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example sorts a two column array. IIf() compares values
// in the second column when adjacent array elements in the
// first column contain identical values.
PROCEDURE Main
LOCAL aArray := { ;
{ "B", 3 }, ;
{ "A", 2 }, ;
{ "B", 1 }, ;
{ "C", 4 }, ;
{ "A", 1 } }
ASort( aArray,,, {|a,b| IIf( a[1] == b[1], ;
a[2] < b[2], ;
a[1] < b[1] ) } )
AEval( aArray, {|a| Qout( ValToPrg(a) ) } )
// result:
// { "A", 1 }
// { "A", 2 }
// { "B", 1 }
// { "B", 3 }
// { "C", 4 }
RETURN
http://www.xHarbour.com