Specifications
BASIC Stamp II
Page 280 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Lookdown with Variables and Comparison Operators
The examples above show Lookdown working with lists of constants,
but it also works with variables. Check out this example that searches
the cells of an array:
value var byte
result var nib
a var byte(7)
value = 17
result = 15
a(0)=26:a(1)=177:a(2)=13:a(3)=1:a(4)=0:a(5)=17:a(6)=99
LOOKDOWN value,[a(0),a(1),a(2),a(3),a(4),a(5),a(6)],result
debug "Value matches item ",dec result," in the list"
Debug prints, “Value matches item 5 in list” because a(5) is 17.
All of the examples above use Lookdown’s default comparison opera-
tor of = that searches for an exact match. But Lookdown also supports
other comparisons, as in this 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
that 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 Look-
down only cares about the first true condition. This can require a cer-
tain 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 inter-
nally 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.










