SELECT CASE

From QB64 Wiki
Revision as of 05:37, 30 August 2009 by imported>Clippy (Created page with ''''SELECT CASE''' is used to automatically determine a program decision by checking the value of a variable. ''Syntax:'' SELECT CASE variable * Variable can be a string or …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

SELECT CASE is used to automatically determine a program decision by checking the value of a variable.



Syntax: SELECT CASE variable


  • Variable can be a string or numerical type.
  • The CASEs should cover the normal ranges of the variable values(use CASE ELSE if necessary.
  • The routine will execute code in the FIRST CASE found to be true and end selecting.



Example:

a = 100
SELECT CASE a
CASE 5
PRINT "This will not be shown."
CASE 10
PRINT "This will not be shown."
CASE 50
PRINT "This will not be shown."
CASE 100
PRINT "This will be shown. (a is 100)"
PRINT "(and this)"
CASE 150
PRINT "This will not be shown."
CASE IS < 150
PRINT "This will not be shown. (a which is 100 is under 150)"
CASE 50 TO 150
PRINT "This will not be shown. (a which is 100 is between 50 TO 150)"
CASE ELSE
PRINT "This will only print if it gets this far!"
END SELECT