BASIC stamp manual v2.2
5: BASIC Stamp Command Reference – SELECT...CASE
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 389
Value1 TO Value2
This indicates a range of Value1 to Value2, inclusive. For example, 20 TO
23 means 20, 21, 22 and 23. Similarly, “A” TO “F” means all the characters
in the range “A” through “F”.
Finally, multiple conditions can be included in a single CASE by
separating them with commas ( , ). For example,
CASE 20, 25 TO 30, >100
will evaluate to True if the Expression (from the SELECT statement) is
equal to 20, or is in the range 25 through 30, or is greater than 100.
An example will help clarify this function.
'{$PBASIC 2.5}
guess VAR WORD
DEBUG "Guess my favorite number: " ' prompt user
DO
DEBUGIN DEC Guess ' get answer
SELECT guess
CASE < 100 ' less than 100?
DEBUG CR, "Not even close. Higher."
CASE > 140 ' greater than 140?
DEBUG CR, "Too high."
CASE 100 TO 120, 126 TO 140 ' 100-120 or 126-140?
DEBUG CR, "Getting closer..."
CASE 123 ' 123? Got it!
DEBUG CR, "That’s it! 123!"
DEBUG CR, "Good Guessing!"
STOP
CASE 121 TO 125 ' close to 123?
DEBUG CR, "You’re so close!"
ENDSELECT
DEBUG CR, "Try again: " ' encourage another try
LOOP
This program will ask the user to guess a number, store that value in guess
and check the results in the SELECT statement. If guess is less than 100,
the first CASE is true and BASIC Stamp will display “Not even close.