GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Download
  • News
  • Community
  • Resources
  • Language Reference
  • SmallBASIC Manual

This view

  • Original page
  • New address

GeezerVison is showing smallbasic.github.io — SmallBASIC | SELECT

Edit History

SELECT

SELECT CASE expr

Home > Reference > Language

Perform multiple tests on the expression expr. Offers a more concise syntax to writing successive IF tests. Once a case statement is fulfilled 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

x = 12 ' Change value to see what happens
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

x = 2
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

x = 4 ' Change value to see what happens
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 = x
    else
        r = x + 1
    endif
    return r
end

func uneven(x) 
    local r
    if(x mod 2 != 0)
        r = x
    else
        r = x + 1
    endif
    return r
end

x = 2 ' Change value to see what happens
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   agendus.bas   betrayal: crows ii.bas   biorythms.bas   block.bas   bowling7.bas   calc.bas   checkers.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   hangman v2.bas   heap.bas   illuminati.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  
This page was last edited on Mon, 19 May 2025 20:44:43 +0930 | Markdown processed with pandoc 3.1.12.1
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.