ElseIf
An IF statement with an ELSEIF condition is the most complicated type of IF statement:
- If the first logical expression is true, the statement block after IF is executed until the first ELSEIF statement is reached.
- If the first logical expression is false, the first ELSEIF logical expression is evaluated.
- If the ELSEIF logical expression is true, the statement block from the ELSEIF to the next ELSEIF (or ELSE) is executed.
- If the ELSEIF statement is false, the next ELSEIF is evaluated.
- If all logical expressions are false, control passes to the ELSE block.
- If there is no ELSE block, control passes to the statement following the END keyword.
An ELSEIF statement is considered part of the same IF statement. Only one END keyword is needed to end an IF, ELSEIF, ELSE statement. IF statements can be nested inside other IF statements. A nested IF statement requires its own END keyword. A missing or mismatched keyword results in a runtime syntax error.
Example
Here is a sample IF statement with ELSEIF condition:
IF (@("FirstAmount") < 1000.00)
$FinalAmount = @("FirstAmount") * .05;
ELSEIF @("FirstAmount") < 5000.00
$FinalAmount = @("FirstAmount") * .03;
ELSEIF @("FirstAmount") < 10000.00
$FinalAmount = @("FirstAmount") * .02;
ELSE
$FinalAmount = @("FirstAmount") + 10.00;
END;
RETURN ($FinalAmount)
If the value of the section variable field FirstAmount is less than 1000.00 then the amount is multiplied by .05 and entered in the target variable $FinalAmount.