VB.NET - Doubt with the statement If and its closure End If

1

Good, someone would tell me why the End If statement is not used when we open with Else If ?

If (num < 0) Then
    Console.WriteLine("El numero es negativo.")
ElseIf (num = 0) Then
    Console.WriteLine("El numero es 0.")
Else
    Console.WriteLine("El numero es positivo.")
End If

If (num = 0) Then
    Console.Write("Se ingresó el cero.")
Else
    If (num > 0) Then
        Console.Write("Se ingresó un valor positivo.")
    Else
        Console.Write("Se ingresó un valor negativo.")
    End If
End If

In the first one when I use ElseIf it is not necessary to close it with End If , on the other hand in the second when I use Else and "below" "the If , there if I need to close it with a End if . Could someone explain to me why? Which of the two solutions should you use?

Thank you.

    
asked by Popplar 27.03.2017 в 05:28
source

1 answer

0

Because the Else If is an additional condition just like a If plus, that's why you can use Else at the end to contradict all the conditions you have written.

    
answered by 21.04.2017 в 09:20