|
Default | |||||
Select <.expression.> ... Case <.expression.> ... Default ... EndSelect | |||||
Parameters: NONE | |||||
Returns: NONE | |||||
Select / Case statements are an alternative to If / Then statements when you have a large number of conditions to examine. The simplest form of a Select / Case block looks like this
If the variable myInt equals 1 this example will output The first case if myInt equals 2, it will output The second case. All other values of myInt will cause no output at all. In order to process all cases that are not explicitely stated with the Case keyword, you can use the keyword Default:
This example would output myInt is neither 1 nor 2 if the value of myInt is less than 1 or greater than 2. You can also check for value ranges with in the case statements by using the keyword To.
If certain conditions apply to a number of unrelated values, you can list these values after the case keyword, separated by commas:
By default PlayBASIC will exit a Select/EndSelect block as soon as a case match occurs. In order to force PlayBASIC to check further cases, use the ContCase statement:
Select/Case statements work with all standard types, ie. Integer, Float and String. Opposed to a lot of other Basic dialects, PlayBasic also accepts expressions after the Case keyword. The expression followed by the Select keyword must be of the same type as the expressions or constants followed by the Case statements. Otherwise PlayBasic will return an error. |
Related Info: | Case | ContCase | EndSelect | if | Select : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |