5: BASIC Stamp Command Reference – IF…THEN
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 151
IF -99 < 100 THEN IsLess
DEBUG "Greater than or equal to 100"
END
IsLess:
DEBUG "Less than 100"
END
Although –99 is obviously less than 100, the program will say it is greater.
The problem is that –99 is internally represented as the two’s complement
value 65437, which (using unsigned math) is greater than 100. This
phenomena will occur whether or not the negative value is a constant,
variable or expression.
IF...THEN supports the conditional logic operators NOT, AND, OR, and
XOR. See Table 5.24 for a list of the operators and their effects.
The NOT operator inverts the outcome of a condition, changing false to
true, and true to false. The following IF...THENs are equivalent:
IF x <> 100 THEN NotEqual ' Goto NotEqual if x is not 100.
IF NOT x = 100 THEN NotEqual ' Goto NotEqual if x is not 100.
The operators AND, OR, and XOR can be used to join the results of two
conditions to produce a single true/false result. AND and OR work the
same as they do in everyday speech. Run the example below once with
AND (as shown) and again, substituting OR for AND:
Value1 VAR BYTE
Value2 VAR BYTE
Value1 = 5
Value2 = 9
IF Value1 = 5 AND Value2 = 10 THEN True ' Change AND to OR and see
DEBUG "Statement was false." ' what happens.
END
True:
DEBUG "Statement was true."
The condition “Value1 = 5 AND Value2 = 10” is not true. Although
Value1 is 5, Value2 is not 10. The AND operator works just as it does in
English; both conditions must be true for the statement to be true. The OR
operator also works in a familiar way; if one or the other or both
conditions are true, then the statement is true. The XOR operator (short
for exclusive-OR) may not be familiar, but it does have an English
NOTE: For BS1's, change line 1
and 2 to:
SYMBOL Value1 = B0
LOGICAL OPERATORS (NOT, AND,
OR
AND XOR).
NOTE: The NOT operator is not
available on the BS1.
NOTE: The XOR operator is not
available on the BS1.
NOTE: The XOR operator is not
available on the BS1.