IF, ELSE, ELSEIF, ENDIF

Conditional execution of statements in a custom function.

Syntax #1:

IF(parameter)

When IF has only a single parameter, it signals the start of an IF … ENDIF sequence. The parameter is a condition: if it is TRUE, execution follows on the following line; if it is FALSE, execution continues after the next ELSE, ELSEIF or ENDIF statement that follows. For example:

IF(@parameter_1 > 10)
  SET_VALUE(C10, 1)
ELSEIF(@parameter_1 > 8)
  SET_VALUE(C12, 1)
ELSEIF(@parameter_1 > 6)
  SET_VALUE(C14, 1)
ELSE
  SET_VALUE(C16, 1)
ENDIF

ENDIF marks the end of the sequence, ELSEIF marks the beginning of a second condition, and ELSE a statement to be executed if the preceding conditions evaluated to FALSE.

You can nest IF statements inside each other, and it is advisable to use spaces to make IF statements more readable:

IF(A15 > B15)
  IF(TYPE(DEREF(C16))="error")
    RESULT("Bad value")
  ENDIF
  C16+4+SUM(E1:E10)
ENDIF


Syntax #2:

IF(parameter_1, parameter_2 {, parameter_3})

If the condition expressed in parameter_1 is TRUE, then parameter_2 is executed. If it is FALSE, execution continues or if a third parameter is supplied, that is executed. You should not use an ENDIF statement to mark the end of the sequence.

Examples:

IF(B3 > 7, RESULT(C3))
IF(B5 = 2,, BREAK)
IF(@num <= 0, RESULT(1), RESULT(@num))