Select-Case statements work like IF ... THEN ... ELSEIF statements. The difference is that the Select-Case statement can make the code simpler to read and work with than IF .. THEN ... ELSEIF statements.
Syntax:
SELECT CASE
CASE test 1
[statement 2]
CASE test 2
[statement 2]
........................
.......................
CASE ELSE
[statement]
END SELECT
Example 1
CLS
INPUT "Enter your percentage "; p
SELECT CASE p
CASE 80 TO 100
div$ = "Distinction"
CASE 60 TO 80
div$ = "First Division"
CASE 40 TO 60
div$ = "Second Division"
CASE 35 TO 40
div$ = "Third Division"
CASE ELSE
div$ = "Fail"
END SELECT
PRINT "Division :: "; div$
END
Example 2
CLS
INPUT "Enter First Number "; x
INPUT "Enter Second Number "; y
PRINT "****** MENU *******"
PRINT "1. Addition"
PRINT "2. Subtraction"
PRINT "3. Multiplication"
PRINT "4. Division"
INPUT "Enter your choice ! (1/2/3/4) "; ch
SELECT CASE ch
CASE 1
PRINT "Sum = "; x + y
CASE 2
PRINT "Difference = "; x - y
CASE 3
PRINT "Product = "; x * y
CASE 4
PRINT "Quotient = "; x / y
CASE ELSE
PRINT "Incorrect choice !!!"
END SELECT
END