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
SYMBOL Value2 = B1
1
L
OGICAL
O
PERATORS
(NOT, AND,
OR
AND
XOR).
1
NOTE: The NOT operator is not
available on the BS1.
1
NOTE: The XOR operator is not
available on the BS1.
NOTE: The XOR operator is not
available on the BS1.
1
Содержание BASIC Stamp 2e
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...