SELECT-CASE-END SELECT/de

From MCS Wiki AVR
< SELECT-CASE-END SELECT
Revision as of 20:14, 15 February 2013 by Admin (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

= (**COPIED FROM ENGLISH PAGE**) === Action

Executes one of several statement blocks depending on the value of an expression.

 

 

Syntax

SELECT CASE var

  CASE test1 : statements

[CASE test2 : statements ]

CASE ELSE : statements

END SELECT

 

 

Remarks

Var

Variable to test the value of

Test1

Value to test for.

Test2

Value to test for.

 

 

You can test for conditions to like:

 

CASE IS > 2 :

 

Another option is to test for a range :

 

CASE 2 TO 5 :

 

 

See also

IF THEN

 

 

 

Example


'-----------------------------------------------------------------------------------------
'name                     : case.bas
'copyright                : (c) 1995-2005, MCS Electronics
'purpose                  : demonstrates SELECT CASE statement
'micro                    : Mega48
'suited for demo          : yes
'commercial addon needed  : no
'-----------------------------------------------------------------------------------------
 
$regfile = "m48def.dat"                                   ' specify the used micro
$crystal = 4000000                                         ' used crystal frequency
$baud = 19200                                               ' use baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space
 
 
Dim I As Byte                                             'dim variable
Dim S As String * 5 , Z As String * 5
 
Do
 
Input "Enter value (0-255) " , I
Select Case I
  Case 1 : Print "1"
  Case 2 : Print "2"
  Case 3 To 5 : Print "3-5"
  Case Is >= 10 : Print ">= 10"
  Case Else : Print "Not in Case statement"
End Select
Loop
End
 
'note that a Boolean expression like > 3 must be preceded
'by the IS keyword

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language