Qbasic Tutorial for beginners and children (Under Construction)


Making Decisions (continued)

The SELECT CASE statement

The SELECT CASE statement is another way to make decisions in BASIC.

The syntax is as follows:

SELECT CASE testexpression
    CASE expressionlist1
        [statementblock-1]
    CASE expressionlist2
        [statementblock-2]]...
    CASE ELSE
       
[statementblock-n]]
END SELECT

Example

The example below illustrates how to use the select case statement
Algorithm Program Code

Display the menu

Get user choice

Select choice: 

  case choice = 1

   Say "You have chosen to play Tetris"

  case choice = 2

   Say "You have chosen to play Hangman"

  case choice = 3

   Say "Goodbye"

  case choice = 4

   Say "Wrong choice"

End select

 

'Designing menu
PRINT "1. Play Tetris"
PRINT "2. Play Hangman"
PRINT "3. Exit"
INPUT "Enter your choice"; choice
SELECT CASE choice
  CASE 1
     PRINT "You have chosen to play Tetris"
  CASE 2
     PRINT "You have chosen to play Hangman"
  CASE 3
     PRINT "Goodbye"
     END
  CASE ELSE
     PRINT "wrong choice"
END SELECT

[ Previous Index Next ]


pages viewed since January  19 2002