Translate

Friday 7 June 2013

Nested If Else in VB.NET with Get Day Name Example



Nested If Else

In this blog we are going to see Nested If Else in VB.NET. Let us see the syntax


If Condition1 Then
Statements
Esle If Condition2 Then
Statements
Else If Condition3 Then
Statements
Else
Statements
End If

The above syntax first check the If Condition1 if it is true the statements followint the Condition1 will be executed and goes to End if , If it is false then check the Condition2 and it is true then Statements follows that Condition will be executed If it is false then checks the Condition3 and statements follows that condition will be executed if all the 3 Conditions occur false then Statements in the Else will be executed.

Let us see an example of finding day by inputing day number.

Module Example8
    Sub main()
        Dim DayNum As Integer
        Console.Write("Enter a Day Number1-7 :")
        DayNum = Console.ReadLine()
        If DayNum = 1 Then
            Console.WriteLine("Sunday")
        Else If DayNum = 2 Then
           Console.WriteLine(" Monday")
Else If DayNum = 3 Then
           Console.WriteLine(" Tuesday)
Else If DayNum = 4 Then
           Console.WriteLine(" Wednesday")
Else If DayNum = 5 Then
           Console.WriteLine(" Thursday")
Else If DayNum = 6 Then
           Console.WriteLine(" Friday")
Else If DayNum = 7Then
           Console.WriteLine(" Saturday")
Else
Console.WriteLine("Invalid Input")
        End If
    End Sub
 End Module



1 comment:

  1. Slots casino site - Lucky Club Live Casino
    Casino site luckyclub.live in India - No signup required, instant withdrawal, welcome bonus, All your favourite casino games online at Lucky Club casino.Welcome Bonus: 100% up to ₹1600

    ReplyDelete