Propeller Manual

Table Of Contents
IF – Spin Language Reference
Page 112 · Propeller Manual v1.1
IF
Command: Test condition(s) and execute a block of code if valid (positive logic).
((PUB PRI))
IF Condition(s)
IfStatement(s)
ELSEIF Condition(s)
ElseIfStatement(s)
ELSEIFNOT Condition(s)
ElseIfNotStatement(s)
ELSE
ElseStatement(s)
Condition(s) is one or more Boolean expressions to test.
IfStatement(s) is a block of one or more lines of code to execute when the IF’s
Condition(s) is true.
ElseIfStatement(s) is an optional block of one or more lines of code to execute when all
the previous Condition(s) are invalid and the
ELSEIF’s Condition(s) is true.
ElseIfNotStatement(s) is an optional block of one or more lines of code to execute when
all the previous Condition(s) are invalid and the
ELSEIFNOT’s Condition(s) is false.
ElseStatement(s) is an optional block of one or more lines of code to execute when all
the previous Condition(s) are invalid.
Explanation
IF is one of the three major conditional commands (IF, IFNOT, and CASE) that conditionally
executes a block of code.
IF can optionally be combined with one or more ELSEIF
commands, one or more
ELSEIFNOT commands, and/or an T ELSE command to form
sophisticated conditional structures.
IF tests Condition(s) and, if true, executes IfStatement(s). If Condition(s) is false, the
following optional
ELSEIF Condition(s), and/or ELSEIFNOT Condition(s), are tested, in order,
until a valid condition line is found, then the associated ElseIfStatement(s), or
ElseIfNotStatement(s), block is executed. The optional ElseStatement(s) block is executed if
no previous valid condition lines are found.
A “valid” condition is one that evaluates to
TRUE for a positive conditional statement (IF or
ELSEIF) or evaluates to FALSE for a negative conditional statement (ELSEIFNOT).