QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

See SELECT CASE.

CASE is used within a SELECT CASE block to specify a conditional value of the compared variable.

Syntax

CASE comparisonValues[:] {code}

Description

*comparisonValues can be any literal string or number, depending on the value specified in the SELECT CASE statement. *Code is executed until the next case, so each case can handle multiple lines of code.

Example(s)


a = 100
SELECT CASE a
   CASE 1, 3, 5, 7, 9: PRINT "Odd values under 10 will be shown."
   CASE 10: PRINT "10 will be shown."
   CASE 50: PRINT "50 will be shown."
   CASE 100: PRINT "This will be shown. (a is 100)"
             PRINT "(and this)"
   CASE 150: PRINT "150 will be shown."
   CASE IS < 150: PRINT "Less than 150 will be shown. (a which is 100 is under 150)"
   CASE 50 TO 150: PRINT "50 to 150 will be shown. (a which is 100 is between 50 TO 150)"
END SELECT


Returns:


 This will be shown. (a is 100)
 (and this)


Explanation: SELECT CASE compares the variable’s value to each descending CASE until ONE is true, executes the CASE code and exits the SELECT CASE. CASE statements should be placed in a increasing or decreasing order for the best results.

What happens is that since 5 isn’t 100 then the code until the next CASE is ignored, the same obviously goes for 10 and 50 but then comes 100 which is what a is so the code in that CASE is executed.

See Also