Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

IF ... THEN ... ELSE

Syntax:

if <any relation> [and | or <any relation>] then <statements> [else <statements>]

or, since version 2.1:

if <any relation> [and | or <any relation>] then
  <statements>
[else
  <statements>]
endif

Conditional structure. Executes the statements after THEN if the expression evaluates to true, otherwise the statements after ELSE, if present. ELSE is optional.

Current limitations:

  • Only one conditional operation (AND/OR) is supported
  • THEN may not be omitted

Examples:

if x >= y/z then print "yes, expression is true"
if a = b then print "they are equal" else print "they are not equal"
if a = b or a < 2 then print "they are equal or a is less than two"

Please refer to the Operators page for the list of supported operators.

Performance tip

An ON … GOTO or ON … GOSUB construct is faster than its IF … THEN GOTO/GOSUB equivalent. Please refer to the ON construct for details.