Selection

[ Back ]

Logic expressions
If and then
If and endif
If, else and endif
If, elseif, else and endif

Logic expressions

With the different versions of the selection statement (the if statement, that is), you can use logic expressions to control the program flow.

A logic expression can use the following operators:

SymbolExampleMeaning
=a = btrue if expression a is equal to expression b
<>a <> btrue if a is not equal to be
<a < btrue if a is less than b
>a > btrue if a is greater than b
<=a <= btrue if a is less than or equal to b
>=a >= btrue if a is greater than or equal to b
anda and btrue if expression a and b are both true
ora or btrue if expression a, b or both are true

During evaluation the operators have the following priorities (highest first):

*
/, %
+, -
=, <>, <, >, <=, >=
and, or

, where % is the modulus operator. But, of course, parenthesis can be used to force precendence.

If and then

if logic expr then statement

If the logic expression evaluates to true, the one statement is performed.

If and endif

if logic expr
  statement
  ...
endif

If the logic expression evaluates to true, all the statements between the if and endif lines are performed.

If, else and endif

if logic expr
  statement
  ...
else
  statement
  ...
endif

If the logic expression evaluates to true, the statements between the if and else lines are performed, else the statements between else and endif are performed.

If, elseif, else and endif

if logic expr
  statement
  ...
elseif logic expr
  statement
  ...
  ...
[else
  statement
  ...]
endif

If the first expression evaluates to true, the statements between if and elseif are performed. Else the second expression is evaluated to se if the lines between elseif and another elseif, else or endif are to be performed.

[ Back ]