IF...ENDIF
Syntax
![]()
Command
Mandatory parameter Optional parameter Mandatory keyword Optional keyword |
There are different ways in which the IF...ENDIF command can be used:
Multiple line version
IF <condition>
<code>
[ELSEIF <condition>
<code>
[ELSEIF <condition>
<code>
...
[ELSE
<code>]]]
ENDIF
Single line version
IF <condition> THEN <instruction> [ELSE <instruction>]
Description
Multiple line version
Creates a branch where the condition controls which code will be executed. If the condition evaluates "True" then the first part until ELSE will be executed. If the condition evaluates "False" then, if specified, the ELSEIF statements will be executed until a condition evaluates "True". If both the IF condition and all the ELSEIF conditions (if applicable) evaluate "False", then code between ELSE and ENDIF will be executed. In contradiction with the IF...THEN...ELSE construction, the beginning of code elements within this statement and also the keywords ELSEIF, ELSE and ENDIF must be written on a new line.
Single line version
Works the same as the multi line IF...ELSE...ENDIF construction. However, the THEN and ELSE keyword must always be written on the same line as the <condition>, no ELSEIF's are allowed, only single instructions can be executed and the ENDIF keyword is not included.
Diagram
Multiple line version
Single line version
Returned value type
None
Parameters
Multiple line version
Parameter | Description |
<Condition> | Expression evaluating to true or false. If the condition contains one or more operands of the type
Realstring that are not part of a nested operation, the left and right operand of the condition will not
be truncated.
In all other cases both operands in the condition will be truncated first before the comparison is executed. |
<Code> | The code under 'IF' is executed if the condition is evaluated as "True". The code under 'ELSE' is executed if the condition is evaluated as "False". |
Single line version
Parameter | Description |
<Condition> |
Expression evaluating to true or false. If the condition contains one or
more operands of the type Realstring that are not part of a nested
operation, the left and right operand of the condition will not be
truncated.
In all other cases both operands in the condition will be truncated first before the comparison is executed. |
<Instruction1> | A single instruction that is executed if the condition is evaluated as "True". |
<Instruction2> | A single instruction that is executed if the condition is evaluated as "False". |
Examples
Multiple line version
sa-100 += ' (Collect)'
elseif q_boekcharge.betkon = 'A'
sa-100 += ' (All-in)'
elseif q_boekcharge.betkon = 'V'
sa-100 += ' (VAT-free)'
else
sa-100 += ' (Unknown)'
endif
Single line version
if s-month <= 3 then process-q1 ()