Skip to content

Overview of Conditional Statements

IF executes a block when a condition is true. UNLESS is its negative form and executes a block when the condition is false.

IF (score >= passing_score)
{
  passed := TRUE;
}

UNLESS (initialized)
{
  initialize();
}

Conditions use BOOL. For a pointer or another type with an affirmative state, write the booliation test explicitly:

IF (pointer??)
{
  use(pointer->);
}

Alternative selection

ELSE IF, ELSE UNLESS, and a final ELSE form a conditional chain:

IF (value < 0)
{
  category := -1;
}
ELSE IF (value == 0)
{
  category := 0;
}
ELSE
{
  category := 1;
}

Conditions are checked from left to right. Only the first selected branch executes. Variables declared inside a branch are local to that branch, so declare an output before the chain when later code needs it.

VAR magnitude I32;
IF (value < 0)
{
  magnitude := 0 - value;
}
ELSE
{
  magnitude := value;
}

Branch likelihood

Place LIKELY or UNLIKELY after IF or UNLESS and before the condition:

IF LIKELY (ready)
{
  process();
}
ELSE IF UNLIKELY (retry)
{
  retry_operation();
}

The hint describes the likelihood of entering that statement's first block. For UNLESS, that is the block entered when its condition is false. Hints inform optimization and do not change evaluation or branch semantics.

Reference

See the Conditional Statements Reference for conversion to BOOL, exact chain evaluation, branch scope, lifetime-state convergence, and the distinction from STATIC_IF, MATCH, and INCLUDE_IF.