BASIC stamp manual v2.2

LOOKDOWN – BASIC Stamp Command Reference
Page 272 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
SYMBOL value = B0
SYMBOL result = B1
value = 17
result = 15
LOOKDOWN value, (26, 177, 13, 1, 0, 17, 99), result
DEBUG "Value matches item ", #result, "in list"
-- or --
value VAR Byte
result VAR Nib
value = 17
result = 15
LOOKDOWN value, [26, 177, 13, 1, 0, 17, 99], result
DEBUG "Value matches item ", DEC result, " in list"
DEBUG prints, “Value matches item 5 in list” because the value (17)
matches item 5 of [26, 177, 13, 1, 0, 17, 99]. Note that index numbers count
up from 0, not 1; that is, in this list, 26 is item 0.
What happens if the value doesn’t match any of the items in the list? Try
changing “Value = 17” to “Value = 2.” Since 2 is not on the list,
LOOKDOWN leaves result unaffected. Since result contained 15 before
LOOKDOWN executed, DEBUG prints “Value matches item 15 in list.”
By strategically setting the initial value of result, as we have here, your
program can be written to detect when an item was not found in the list.
Don’t forget that text phrases are just lists of byte values, so they too are
eligible for LOOKDOWN searches, as in this example:
SYMBOL value = B0
SYMBOL result = B1
value = "f"
result = 255
LOOKDOWN value, ("The quick brown fox"), result
DEBUG "Value matches item ", #result, "in list"
-- or --
T
HE INDEX NUMBER OF THE FIRST ITEM IS
0, NOT 1.
U
SING TEXT IN THE VALUE LIST.
1
All
2
1