BASIC stamp manual v2.2

SELECT...CASE – BASIC Stamp Command Reference
Page 388 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Explanation
SELECT…CASE is an advanced decision-making structure that is often
used to replace compound IF…THEN…ELSE structures. SELECT…CASE
statements are good for performing one of many possible actions
depending on the value of a single expression.
Upon reaching a SELECT…CASE statement, the BASIC Stamp will
evaluate Expression once and then compare it to the Condition(s) of each
CASE until it finds a “case” that evaluates to True, or it runs out of cases to
compare to. As soon as a True case is found, the BASIC Stamp executes
that CASE’s Statement(s) and then continues execution on the program line
following ENDSELECT.
To understand how SELECT…CASE statements work, it helps to review
how IF…THEN statements behave. The condition argument of IF…THEN
takes the form:
Value1 Comparison Value2
and Value1 is “compared” to Value2 using the Comparison operator.
In SELECT...CASE statements, the Value1 component is always Expression
and so the format of Condition(s) is simplified to:
{ Comparison } Value
Comparison is optional and can be any of the comparison operators shown
in Table 5.93. If Comparison is not specified, it is an implied Equal ( = )
operator. Value can be a variable, constant or expression.
Comparison Operator Symbol Definition
=
Equal
<>
Not Equal
>
Greater Than
<
Less Than
>=
Greater Than or Equal To
<=
Less Than or Equal To
Table 5.93: Comparison Operators
for SELECT...CASE.
Condition(s) also has a special, additional format that can be used to
indicate a range of sequential values: