SELECT
SELECT CASE expr
Perform multiple tests on the expression expr
. Offers a
more concise syntax to writing successive IF tests. Once a case
statement is fullfilled the select-case structure will be exited and all
following case statements will not be tested anymore.
See also IF … THEN … ELIF … ELSE … FI structure.
Example 1: Basic select-case expression
12 ' Change value to see what happens
x = select case x
case 12
print "x is 12"
case 13,14,15
print "x is 13,14,or 15"
case else
print "x is not 12,13,14,15"
end select
Example 2: Exit of a select structure once a test was successful
2
x = select case x
case 2
print "x is 2"
case 2
print "This will never be printed"
end select
Example 3: Use IFF to check a range
4 ' Change value to see what happens
x = select case x
case iff(x <= 4, x, x + 1)
print "x <= 4"
case iff(x > 4 AND x < 12, x, x + 1)
print "4 < x < 12"
end select
Example 4: Using functions
func even(x)
local r
if(x mod 2 == 0 AND x != 0)
r = xelse
1
r = x + endif
return r
end
func uneven(x)
local r
if(x mod 2 != 0)
r = xelse
1
r = x + endif
return r
end
2 ' Change value to see what happens
x = select case x
case even(x)
print "x is even"
case uneven(x)
print "x is uneven"
case else
print "x is 0"
end select
Code samples using SELECT
000 hello.bas
001 3 ways to print hello 5 times.bas
002 numeric variables.bas
003 conditional branching.bas
004 loops.bas
005 challenge.bas
006 arrays+.bas
2048.bas
2048.bas
agendus.bas
betrayal: crows ii.bas
biorythms.bas
block.bas
bowling7.bas
calc.bas
checkers.bas
checkers.bas
chess.bas
chess.bas
dia de una fecha.bas
doodle.bas
Euro_calculator.bas
filemanager.bas
form demo.bas
g5 Life.bas
g6 Life.bas
gputmalc.bas
graphics sampler.bas
GUI RPSLS v2.bas
Language
AND
AS
BAND
BG
BOR
BYREF
CALL
CASE
CATCH
CONST
DECLARE
DEF
DO
ELIF
ELSE
ELSEIF
END
END TRY
ENDIF
EQV
EXIT
FALSE
FI
FOR
FUNC
GOSUB
GOTO
IF
IFF
IMP
IN
LABEL
LET
LIKE
LOCAL
LSHIFT
MDL
MOD
NAND
NEXT
NOR
NOT
ON
OR
REM
REPEAT
RETURN
RSHIFT
SELECT
STEP
STOP
SUB
THEN
THROW
TO
TRUE
TRY
UNTIL
USE
USG
USING
WEND
WHILE
XNOR
XOR
If there is insufficient information on this page and you wish learn more about SELECT,
please send an email to smallbasic@gmail.com. You can help to improve information about
SELECT by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.