BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – LOOKDOWN
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 273
value VAR Byte
result VAR Nib
value = "f"
result = 255
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 all BS2 models, 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.53. 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 (Table 5.53) 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
LOOKDOWN CAN USE VARIABLES AND
EXPRESSIONS IN THE VALUE LIST
.
U
SING LOOKDOWN'S COMPARISON
OPERATORS
.
W
ATCH OUT FOR UNSIGNED MATH
ERRORS WHEN USING THE COMPARISON
OPERATORS
.
All
2
All
2