IF statement in Visual Basic .Net

You can use the IF statement in programming to make decision
This is how you write the IF… Then statement in visual basic.

Dim number As Integer = 12
If number > 10 Then
Console.WriteLine(“Number is greater than 10”)
End If

First you declare the variable and assign the number 12 for it
Then you can check the number is greater than 1o. If the number is greater than 10 you can write the message to console

You can end the code block with End If. You can write whatever code inside the If … End If code block. This code block will ring if the condition is true

If you want to run another piece of code when condition is false you can use the Else statement here

Dim number As Integer = 12
If number > 10 Then
Console.WriteLine("Number is greater than 10")
Else
Console.WriteLine("Number is not greater than 10")
End If

Suppose you can test another condition, for example you want to check the number whether it is less than zero, you cause use Else If

Dim number As Integer = 12
If number > 10 Then
Console.WriteLine(“Number is greater than 10”)
ElseIf number < 0 Then Console.WriteLine("Number is less than 0") End If

Leave a Reply

Your email address will not be published. Required fields are marked *