if/then/else

if-then and if-then-else statements execute code conditionally based on a boolean expression.

Syntax

if
Introduces the conditional part of the statement where you define the condition to evaluate:
  • If the condition is true, the statements in the then block are executed.
  • If the condition is false, the statements in the else block are executed (if present)
then
Introduces the block of statements executed when the condition evaluates to true. Statements execute sequentially in the order they appear.

Each statement must end with a semicolon (;).

else
Introduces the block of statements executed when the condition evaluates to false. Statements execute sequentially in the order they appear.

Each statement must end with a semicolon (;).

end
All if-then and if-then-else statements must terminate with the end keyword.

Simple if-then

Executes statements only when the condition is true.

Syntax
if <condition> then 
   <statements> 
end
Example
if result is null then
    set result to "";
end

if-then-else

Executes one block when the condition is true, another when false.

Syntax
if <condition> then 
    <statements> 
else 
    <statements> 
end
Example
declare 'x' being 123 ;
if x is more than 0 then
    set result to "positive";
else
    set result to "negative";
end
Expected output
"positive"