User Tools

Site Tools


syntax:functions:if

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
syntax:functions:if [2015/03/27 17:45] elenapsyntax:functions:if [2021/08/11 14:16] craigt
Line 1: Line 1:
-====== If(condition, expression1expression2) ======+====== If(condition, when_truewhen_false) ====== 
 +Category:  Logical function
  
-Returns result of //expression1// if //condition// is true. Otherwise returns result of //expression2//.+\\  
 +=====Description===== 
 +This action creates binary decision logic by evaluating the supplied //condition// and returning the //when_true// value if the condition is true, or //when_false// if not.
  
- Example   Result  +\\  
-if( 2 + 2 = 4, 'Makes sense', 'Nonsense' )  Makes sense  +=====Arguments===== 
-if( 2 + 1 = 4'Makes sense', 'Nonsense' )  Nonsense  |+^Argument^Type^Description
 +|condition|Expression|This is an expression or "test" that evaluates to either TRUE or FALSE.
 +|when_true|Expression|If the //condition// evaluates to TRUEthis value is returned.| 
 +|when_false|Expression|If the //condition// evaluates to FALSE, this value is returned.| 
 +**Return value type:** Text, Number, Boolean (the value types used for //when_true// and //when_false//)
  
 +\\ 
 +=====Remarks=====
 +To return a Boolean TRUE or FALSE value, use the [[syntax:functions:true|True()]] and [[syntax:functions:false|False()]] functions.
 +
 +If() functions can be nested to provide decisions based on more than a single test, and return a value from more than just two choices.  See examples below.
 +
 +\\ 
 +=====Examples=====
 +
 +  if(2+2=4, "Yes it does", "No it doesn't") = "Yes it does"  //Returns the text value.
 +  if("This" = "That", 1, 0) = 0  //Returns numeric zero.
 +  if(rem(4,2)=0,"Number is even","Number is odd") = "Number is even"  //Using a function in the condition.
 +  if({MyVal}+6=8,"MyVal is 2","MyVal is not 2") = "MyVal is not 2"  //Where "MyVal" = 3, parameters are supported.
 +\\ 
 +====Nested if()s====
 +Another "level" of logic can be introduced by using a nested if() for the outer if()'s TRUE and/or FALSE value(s).  This becomes the equivalent of an "elseif" branch.
 +
 +  if( [Field1)>10, "More than 10", if( [Field1]>0, "More than 0, less than 10", "Less than 0" ) )
 +
 +If [Field1] is greater than 10, the condition is evaluated to TRUE and the //when_true// value ("More than 10") is returned.  However, if the condition is evaluated to FALSE, the //when_false// "value" is another if() test, which is evaluated.  In this case, if [Field1] is greater than 0, "More than 0" is returned, otherwise "Less than 0" is.
 +
 +Nested if()s can be used for the //condition//, the //when_true//, and/or the //when_false// values.
 +
 +\\ 
 +===== See also =====
 +  * [[syntax:functions:ifempty|IfEmpty(expression1, expression2)]]
 +  * [[syntax:functions:iferror|IfError(expression1, expression2)]]
 +  * [[syntax:functions:false|False()]]
 +  * [[syntax:functions:true|True()]]
syntax/functions/if.txt · Last modified: 2021/08/16 02:42 by craigt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki