Select Case in Visual Basic
One value against many shapes of branch: lists, ranges, comparisons.
Dim day = "sat"
Select Case day
Case "sat", "sun"
Console.WriteLine("weekend")
Case Else
Console.WriteLine("workday")
End Select
Dim load = 73
Select Case load
Case Is >= 90
Console.WriteLine("critical")
Case 70 To 89
Console.WriteLine("busy")
Case Else
Console.WriteLine("normal")
End Select
How it works
Case "sat", "sun"matches any value in the comma list.Case Is >= 90compares;Case 70 To 89catches a whole range.Case Elsepicks up everything the branches above declined.
Keywords and builtins used here
CaseDimElseEndSelectTo
The run, in numbers
- Lines
- 18
- Characters to type
- 294
- Tokens
- 80
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 53 seconds.
Step 2 of 3 in Control flow, step 8 of 29 in Language basics.