3
Cyanide
3y

It feels so weird to use case clauses without braces, event though it’s allowed.

Comments
  • 2
    ```VisualBasic
    Dim number As Integer = 8
    Select Case number
    Case 1 To 5
    Debug.WriteLine("Between 1 and 5, inclusive")
    ' The following is the only Case clause that evaluates to True.
    Case 6, 7, 8
    Debug.WriteLine("Between 6 and 8, inclusive")
    Case 9 To 10
    Debug.WriteLine("Equal to 9 or 10")
    Case Else
    Debug.WriteLine("Not between 1 and 10, inclusive")
    End Select
    ```
    (source: Microsoft documentation)
  • 1
    Case isn't an isolated code block, it's just a "special" label for the switch statement to jump to. For all other purposes it behaves like a regular label: it doesn't affect the execution of the code in any way. Using brackets with case just makes it less obvious the code actually belongs to the same switch code block and will continue executing unless there's a breaking control statement (break, return, throw).
Add Comment