SELECT CASE
A conditional branching structure to allow definition of multiple different actions to be taken according to the value of an expression or variable
Implemented by: sbasic, ansifull, bwbasic, bw32, QBasic, VBDOS, FreeBASIC, ugBASIC, EndBASIC
With variations: Gambas
Also written as:
Usage
SELECT-CASE is not by itself a BASIC keyword, but the most popular name of a multibranch structure which substitutes a possibly long sequence of IFs and ELSEs.
SELECT-CASE is more often found in structured, not numbered-line versions of BASIC, but it might be found in line-numbered BASICs as well. The ANSI Full specification has some examples, such as:
10 SELECT CASE X 20 CASE IS < 0 30 PRINT X; "is negative" 40 CASE IS > 0 50 PRINT X; "is positive" 60 CASE ELSE 70 PRINT X; "is zero" 80 END SELECT
Variations
Examples
Comments
Related keywords
Similar keywords
In other languages...
The SELECT-CASE structure is very similar to the switch…case structure found in C and descendents such as PHP, Java, Javascript. Tcl also has a switch command which dispenses the case keyword and basically works with string comparison only.
Python had to wait until version 3.10.6 to have a similar structure, match…case.