Specifications
BASIC Stamp II
Page 282 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Lookup
LOOKUP
index, [value0, value1,...valueN], resultVariable
Look up the value specified by the index and store it in a variable. If
the index exceeds the highest index value of the items in the list, vari-
able is unaffected.
•
Index
is the item number (constant or variable) of the value to be
retrieved from the list of values.
•
Value0
,
value1
... make up a list of values (constants or variables)
up to 16 bits in size.
•
ResultVariable
is a variable in which the retrieved value will be
stored (if found).
Explanation
Lookup retrieves an item from a list based on the item’s position (in-
dex) in the list. For example:
index var nib
result var byte
index = 3
result = 255
LOOKUP index,[26,177,13,1,0,17,99],result
debug "Item ", dec index," is: ", dec result
Debug prints “Item 3 is: 1.” Note that Lookup lists are numbered from
0; in the list above item 0 is 26, item 1 is 177, etc. If the index provided
to Lookup is beyond the end of the list the result variable is unchanged.
In the example above, if index were greater than 6, the debug message
would have reported the result as 255, because that’s what result con-
tained before Lookup executed.
Demo Program
This program uses Lookup to create a debug-window animation of a
spinning propeller. The animation consists of the four ASCII charac-
ters | / - \ which, when printed rapidly in order at a fixed location,
appear to spin. (A little imagination helps a lot here.)










