select case ... end select
Conditionally execute code, depending on if expression matches tests.
Syntax:
select case condition expression
case value1
statements to be executed if value1 match
case value2
statements to be executed if value2 match
{case valueN }
{statements to be executed if valueN match}
{case else}
{statements to be executed if none of previous cases match}
end select
condition expression may be a variable or any expression.
select case statement compare expression with a set of values and execute blocks of commands if match. This command permit to test many possible values without use a long list of if...else instructions, this way, it makes your programs more efficient an readable.
Tests can be strung together with commas:
Case 4, 5, 6
and the forms are:
is = expression in this case you can omit is=
is<> expression
is> expression
is< expression
is<= expression
is>= expression
Example:
' Print the name of a number
select case n
case is = 1
print "one"
case 2 ' omitted is= here
print "two"
case 3 ' omitted is= here
print "three"
case 4, 5, 6 ' omitted is= here
print "four, five or six"
case is < 10
print "less than 10"
case else
print "too big!"
end select