Skip to main content

1E 9.x (on-premises)

IF ELSE ENDIF

Keywords

IF ELSE ENDIF

Purpose

Allows conditional branching of instruction flow based on a condition.

Description

Syntax

IF (condition)
   //IF block of statements: SELECT statements, Methods and/or Functions
   //optional 'early exit' termination
ELSE
   //optional ELSE block of statements: SELECT statements, Methods and/or Functions
   //optional 'early exit' termination
ENDIF;

The condition cannot be a SELECT statement, but can be one of the following:

  • A variable, such as “@myTable

  • A method invocation, such as “Network.GetConnections()

  • A literal, such as “1” (although use of this is uncommon)

In each of the above cases, the condition (which represents a table of data) will evaluate to “true” – and will therefore pass the IF check – if that table has one or more rows. A table with zero rows (including tables which have an undefined structure) will evaluate to “false”.

The IF condition is followed by a block of code to execute if the condition evaluates to true, and then a closing ENDIF. You may optionally include an ELSE statement with a corresponding block of code to execute if the condition evaluates to false.

Take care to ensure the output of the IF and ELSE blocks have the same shape, as described in SCALE User Guide: Inconsistent branching results.

Examples

See SCALE User Guide: Conditional branching using IF/ELSE/ENDIF.

Notes