5: BASIC Stamp Command Reference – LOOKDOWN
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 179
LOOKDOWN Value, ["The quick brown fox"], Result
DEBUG "Value matches item ", DEC Result, " in list"
DEBUG prints, “Value matches item 16 in list” because the character at
index item 16 is "f" in the phrase, “The quick brown fox”.
The examples above show LOOKDOWN working with lists of constants,
but it also works with variables and expressions also. Note, however, that
expressions are not allowed as argument on the BS1.
On the BS2, BS2e, BS2sx and BS2p, the LOOKDOWN command can also
use another criteria (other than "equal to") for its list. All of the examples
above use LOOKDOWN’s default comparison operator, =, that searches
for an exact match. The entire list of ComaprisonOps is shown in Table 5.36.
The "greater than" comparison operator (>) is used in the following
example:
Value VAR BYTE
Result VAR NIB
Value = 17
Result = 15
LOOKDOWN Value, >[26, 177, 13, 1, 0, 17, 99], Result
DEBUG "Value greater than item ", DEC Result, " in list"
DEBUG prints, “Value greater than item 2 in list” because the first item the
value 17 is greater than is 13 (which is item 2 in the list). Value is also
greater than items 3 and 4, but these are ignored, because LOOKDOWN
only cares about the first item that matches the criteria. This can require a
certain amount of planning in devising the order of the list. See the demo
program below.
LOOKDOWN comparison operators use unsigned 16-bit math. They will
not work correctly with signed numbers, which are represented internally
as two’s complement (large 16-bit integers). For example, the two’s
complement representation of -99 is 65437. So although -99 is certainly
less than 0, it would appear to be larger than zero to the LOOKDOWN
comparison operators. The bottom line is: Don’t used signed numbers
with LOOKDOWN comparisons.
LOOKDOWN
CAN USE VARIABLES
AND EXPRESSIONS IN THE VALUE LIST
.
2
e
2
sx
2
p
2
U
SING
LOOKDOWN'
S COMPARISON
OPERATORS
.
W
ATCH OUT FOR UNSIGNED MATH
ERRORS WHEN USING THE
COMPARISON OPERATORS
.
Содержание BASIC Stamp 1
Страница 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...