BASIC stamp manual v2.2

IF…THEN – BASIC Stamp Command Reference
Page 232 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Quick Facts
BS1 All BS2 Models
Comparison
Operators
=, <>, >, <, >=, <= =, <>, >, <, >=, <=
Conditional
Logic Operators
AND, OR NOT, AND, OR, XOR
Format of
Condition
Variable Comparison Value;
where Value is a variable
or constant
Value1 Comparison Value2;
where Value1 and Value2 can by
any of variable, constant or
expression
Parentheses
Not Allowed Allowed
Max nested
IF…THENs
n/a 16
Max ELSEIFs
per IF
n/a 16
Max ELSEs per IF
n/a 1
Related Command
None SELECT…CASE
Table 5.38: IF...THEN Quick Facts.
Explanation
IF...THEN is PBASIC's decision maker that allows one block of code or
another to run based on the value (True or False) of a condition. The
condition that IF...THEN tests is written as a mixture of comparison and
logic operators. The available comparison operators are:
Comparison Operator
Symbol
Definition
= Equal
<> Not Equal
> Greater Than
< Less Than
>= Greater Than or Equal To
<= Less Than or Equal To
Table 5.39: IF...THEN Comparison
Operators.
Comparisons are always written in the form: Value1 Comparison Value2.
The values to be compared can be any combination of variables (any size),
constants, or expressions.
The following example is an IF…THEN command with a simple
condition:
IF value < 4000 THEN Main
This code will compare the value of value to the number 4000. If value is
less than 4000, the condition is true and the program will jump (implied
NOTE: On the BS1, expressions
are not allowed as arguments.
Also, the Value1 (to the left of
comparison) must be a variable.
1
A SIMPLE FORM OF IF…THEN
1
A
ll
2