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
syntax:functions:if [2016/06/08 00:14] dmitrysyntax:functions:if [2021/08/16 02:42] (current) – [Examples] craigt
Line 1: Line 1:
-====== If(condition, expression1expression2) ======+====== If(condition, when_truewhen_false) ====== 
 +Category:  Logical function
  
-Returns the result of //expression1// if //condition// is true. Otherwise returns the result of //expression2//.+\\  
 +=====Description===== 
 +This function evaluates //condition// and returns 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.
 +
 +Both //when_true// and //when_false// values are always evaluated, even if only one of them is returned.
 +
 +\\ 
 +=====Examples=====
 +
 +  if(2+2=4, "Yes it does", "No it doesn't") //Returns "Yes it does"
 +
 +  if("This" = "That", 1, 0) //Returns 0  (Returns a numeric zero.)
 +
 +  if(rem(4,2)=0,"Number is even","Number is odd") //Returns "Number is even"  (Using a function in the condition.)
 +
 +  if({MyVal}+6=8,"Is 2","Is not 2") //Returns "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.1465359292.txt.gz · Last modified: 2016/06/08 00:14 by dmitry

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki