typestar

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

  1. Case "sat", "sun" matches any value in the comma list.
  2. Case Is >= 90 compares; Case 70 To 89 catches a whole range.
  3. Case Else picks up everything the branches above declined.

Keywords and builtins used here

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.

Type this snippet

Step 2 of 3 in Control flow, step 8 of 29 in Language basics.

← Previous Next →