IF...THEN...ELSE is fine if you only have two things you
want to check. What if you have 5 or 6 friends that might use
your computer and you want the computer to say something different
to each of them? Try this:
INPUT "Enter your name: ", Name$
SELECT CASE Name$
PRINT "Greetings, oh powerful master"
PRINT "Go away!"
PRINT "Hello, "; Name$; ". How are you?"
Whew, that was a big one. Fortunately we learned how to save in
Chapter 8. Save it if you want before running it. Feel free to
change "Ted" and "Mike" to "Laura" and "Robin" or whoever.
SELECT CASE first checks Name$ for the value "Ted". If it finds
it, it does the PRINT after the CASE "Ted". When the PRINT is done,
it skips over the rest of the CASEs. It keeps checking against
each CASE until it gets to CASE ELSE. If it hasn't found anything,
it will do whatever is after the CASE ELSE.
Just In CASE
SELECT CASE can also be used with numbers as well as strings.
Here's a quick example:
INPUT "Enter a number: ", Number
SELECT CASE Number
PRINT "Thank you for entering the secret number 1234"
PRINT "Well, 22 is an interesting number"
PRINT "You must not know the secret number"