VB.Net - If...Then...Else Statement
An If statement can be followed by an optional Else statement, which executes when the Boolean expression is false.
Syntax
The syntax of an If...Then... Else statement in VB.Net is as follows −If(boolean_expression)Then
'statement(s) will execute if the Boolean expression is true
Else
'statement(s) will execute if the Boolean expression is false
End If
If the Boolean expression evaluates to true, then the if block of code will be executed, otherwise else block of code will be executed.
VB.NET PROGRAM
Sub Main()
'local variable definition '
Dim a As Integer = 100
' check the boolean condition using if statement
If (a < 20) Then
' if condition is true then print the following
Console.WriteLine("a is less than 20")
Else
' if condition is false then print the following
Console.WriteLine("a is not less than 20")
End If
Console.WriteLine("value of a is : {0}", a)
Console.ReadLine()
End Sub
End Module
When the above code is compiled and executed, it produces the following result −
None of the value is matching
value of a is : 100
If you liked the tutorial then don’t forget to comment and share!
0 comments:
Post a Comment