QBasic 1.1: SELECT CASE Statement
Explanation
SELECT CASE Statement
Executes one of several statement blocks depending on the value of an expression.
Worth knowing
Useful and cross-version information about the programming environments of QBasic, QuickBasic and Visual Basic for DOS.
Syntax
SELECT CASE testexpression |
CASE expressionlist1 |
[statementblock-1] |
CASE expressionlist2 |
[statementblock-2]... |
CASE ELSE |
[statementblock-n] |
Description / Parameter(s)
testexpression |
Any numeric or string expression. |
expressionlist1 |
One or more expressions to match testexpression. |
expressionlist2 |
The IS keyword must precede any relational operators in an expression. |
statementblock-1 statementblock-2 statementblock-n |
One or more statements on one or more lines. |
The expressionlist arguments can have any of these forms or a combination of them, separated by commas: |
expression[,expression]... expression TO expression IS relational-operator expression |
expression |
Any numeric or string expression compatible with testexpression. |
relational-operator |
One of the following relational operators: <, <=, >, >=, <>, or =. |
|
Example
INPUT "Enter acceptable level of risk (1-5): ", Total
SELECT CASE Total
CASE IS >= 5
PRINT "Maximum risk and potential return."
PRINT "Choose stock investment plan."
CASE 2 TO 4
PRINT "Moderate to high risk and potential return."
PRINT "Choose mutual fund or corporate bonds."
CASE 1
PRINT "No risk, low return."
PRINT "Choose IRA."
END SELECT