VB.Net - Nested Select Case Statement

Advertisements


It is possible to have a select statement as part of the statement sequence of an outer select statement. Even if the case constants of the inner and outer select contain common values, no conflicts will arise.

Example

Module decisions
   Sub Main()
      'local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      Select a
          Case 100
              Console.WriteLine("This is part of outer case ")
              Select Case b
                  Case 200
                      Console.WriteLine("This is part of inner case ")
              End Select
      End Select
      Console.WriteLine("Exact value of a is : {0}", a)
      Console.WriteLine("Exact value of b is : {0}", b)
      Console.ReadLine()
   End Sub
End Module

When the above code is compiled and executed, it produces the following result:

This is part of outer case
This is part of inner case
Exact value of a is : 100
Exact value of b is : 200


Advertisements
Advertisements