Home >>VB.Net Programs >VB.Net program to demonstrate the nested 'select case'

VB.Net program to demonstrate the nested 'select case'

Write a VB.Net program to demonstrate the nested 'select case'

Here, inside the case, we can describe the select case, which is known as the nested 'select case.'

Program :

The source code to show the nested 'select case' is given below. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim choice1 As Integer = 2
        Dim choice2 As Single = 2.2
        Select Case choice1
            Case 1
                Select Case choice2
                    Case 1.1
                        Console.WriteLine("Option 1.1")
                    Case 1.2
                        Console.WriteLine("Option 1.2")
                    Case 1.3
                        Console.WriteLine("Option 1.3")
                End Select
            Case 2
                Select Case choice2
                    Case 2.1
                        Console.WriteLine("Option 2.1")
                    Case 2.2
                        Console.WriteLine("Option 2.2")
                    Case 2.3
                        Console.WriteLine("Option 2.3")
                End Select
            Case 3
                Select Case choice2
                    Case 3.1
                        Console.WriteLine("Option 3.1")
                    Case 3.2
                        Console.WriteLine("Option 3.2")
                    Case 2.3
                        Console.WriteLine("Option 3.3")
                End Select
            Case Else
                Console.WriteLine("Invalid choice")
        End Select
    End Sub
End Module
	
Output:
Option 2.2

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created two variables, choice1 and choice2, in the Main() method, which are initialized with 2 and 2.2 respectively.

We specified "select case" within the "select case" in the program above, which is known as a nested select case. Here, "case 2.2" is executed and the relevant message is then printed on the console screen.


No Sidebar ads