Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt
hiddentrue

if(condition, trueExpression, falseExpression) Processed trueExpression if condition is true, falseExpression if condition is false.


Function: if()

Process an Expression (and return its value) depending on whether a condition evaluates to True or False.

...

  1. if(condition, trueExpression)
  2. if(condition, trueExpression, falseExpression)
ArgumentTypeDescription
conditionBooleanThe condition to be checked
trueExpressionAnyThe expression to be evaluated if condition is True
falseExpressionAnyAn optional expression to be evaluated if condition is False

Note that if you want to process more than a one-line expression if condition evaluates to True or False then wrap the script in a do() function. See the examples below.

...

This example shows how to use a do() function if you want to process several expressions (a script) based on the result of an if(). Note that the $-Variables $priceBand and $rate are only set if in.telNo starts with "44".

...

This example extends the example above to include an "else" clause i.e. the expressions that should be processed if the condition returns False.

Please note Note the layout in the last example. Consistent formatting of your scripts like this will can help clarify where the "else" script starts. Also see Scripting Expression Style.

See Also