IF … THEN … ELSE … ENDIF

This command, logic control statement, executes a true statement block if the condition is evaluated to true, else execute a false statement block.

The condition can be a single expression, or a relational condition consisting of a left-hand expression, a relational operator and a right-hand expression. All expressions in the conditions are evaluated as arithmetic expressions, with a fall-back to text evaluation. See Evaluation of expression for more details.

Single expression conditions
The condition is a single expression (arithmetic or text). For the condition to evaluate to true, the expression must be one of the following:
  • An arithmetic expression and evaluate to a number greater than zero.
  • A text expression and evaluate to the word true (any letter case can be used).
Relational conditions
The format of the relational condition:
<left expression> <conditional operator> <right expression>

The left expression and right expression are evaluated as arithmetic expressions (with possible fall-back to text-based evaluation).

The expressions are compared using the conditional operator after the evaluation. If both expressions evaluate to a number, then arithmetic comparison is used. If one or both expressions evaluate to a text value, or if a text relational operator is used, the text-based comparison is used.

Conditional operators in relational conditions
These arithmetic operators are used in relational conditions:
  • Equals: =

    Examples: 1 = 2 evaluates the condition to false, 2 = 2.0 evaluates to true.

  • Not Equals: !=or <>

    Example: 1 != 2 evaluates to true, 2 != 1 + 1 evaluates to false.

  • Greater than: >

    Examples: 2 > 2 evaluates to false, 2 > $var, with $var=1.0 evaluates to true

  • Greater than or equal: >=

    Examples: 2 >= 2 evaluates to true, 2 >= 1.0 evaluates to false

  • Less than: <

    Examples: 2 < 2 evaluates to false, 1 < 2 evaluates to true.

  • Less than or equal: <=

    Examples: 2 <= 2 evaluates to true, 1 <= 2 evaluates to true

These text operators are used in relational conditions:

  • Equals: =

    Examples: ABCD=ABCD or ABCD=aBcD evaluates to true. A = B evaluates to false.

  • Not Equals: !=or <>

    Example: ABCD!=ABCD or abcd<>ABCD evaluates to false. A != B evaluates to true.

  • Greater than: >

    Examples: A > B evaluates to false, Bc > aB evaluates to true, B > A evaluates to true, A > A evaluates to false.

  • Greater than or equal: >=

    Examples: ABCD >= ABCD evaluates to true, ABCD >= BC evaluates to false.

  • Less than: <

    Examples: ABCD < bCDE evaluates to true, ABCD < BC evaluates to true, B < A evaluates to false, A < A evaluates to false.

  • Less than or equal: <=

    Examples: Examples: ABCD <= AbCD evaluates to true, ABCD <= BC evaluates to true.

  • Contains: ~ (a portion of the left expression matches the right expression)

    Examples: ABCD ~ bc evaluates to true, ABCD ~ something else evaluates to false.

  • Does not contain: !~

    Examples: 12 !~ A evaluates to true, ABCD ~ something else evaluates to false.

Note: 
  • Comparisons performed by text operators are based on the lexicographical order of the compared values.
  • The comparisons are case-insensitive.

These are the examples of ‘IF … THEN … ELSE … ENDIF’ command:

  • Echo “Yes”
    $variable = 11;
    IF $variable > 10 THEN Echo: Yes;
    END IF;
    
  • Echo = No
    $variable = 1;
    IF $variable > 10 THEN Echo: Yes;
    ELSE Echo: No;
    END IF;
    
Conditionally execute multiple commands (run another workflow and an optimization):
$execute = 1;
IF $execute = 1 THEN 
Workflow: another workflow;
Solve: Optimization 1;
END IF;