LOOKDOWN - BASIC Stamp Command Reference
ComparisonOp Symbol
=
<>
>
<
>=
<=
A common application for LOOKDOWN is to use it in conjunction with
the BRANCH command to create selective jumps based on a simple
variable input:
Cmd
VAR BYTE
Cmd = "M"
LOOKDOWN Cmd, ["SLMH"], Cmd
BRANCH Cmd, [_Stop, _Low, _Medium, _High]
DEBUG "Command not in list"
END
_Stop:
DEBUG "stop"
END
_Low:
DEBUG "low"
END
_Medium:
DEBUG "medium"
END
_High:
DEBUG "high"
END
In this example, Cmd contains "M" (ASCII 77). LOOKDOWN finds that
this is item 2 of a list of one-character commands and stores 2 into Cmd.
BRANCH then goes to item 2 of its list, which is the program label
"_Medium" at which point DEBUG prints "medium" on the PC screen.
This is a powerful method for interpreting user input, and a lot neater
than the alternative IF...THEN instructions.
Another great use of LOOKDOWN is in combination with LOOKUP to
"map" non-contiguous sets of numbers together. For example, you may
have an application where certain numbers are received by the BASIC
Stamp and, in response, the BASIC Stamp needs to send a specific set of
numbers. This may be easy to code if the numbers are contiguous, or
follow some know algebraic equations... but what if they don't? The table
Page 180 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
Description
Find the first value Target is equal to
Find the first value Target is not equal to
Find the first value Target is greater than
Find the first value Target is less than
Find the first value Target is greater than or equal to
Find the first value Target is less than or equal to
Table 5.36: LOOKDOWN
Comparison Operators.
U
LOOKDOWN
SING
WITH
.
TO JUMP BASED ON VALUES
NOTE: For BS1's, change line 1 to:
SYMBOL Cmd = B0
And replace the [ and ] symbols
with ( and ) in lines 4 and 5.
U
LOOKDOWN
SING
WITH
"
"
-
TO
MAP
NON
CONTIGUOUS SETS OF
.
NUMBERS
BRANCH
LOOKUP
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?