22-Logical Operators

0
374

This Visual Basic tutorial is all about Logical Operators.
Logical operators is similar to Boolean expressions that return a boolean result. These And, Or, AndAlso, OrElse, and Xor operators are called binary because they acquire two operands. But  there is one operator that is not binary and it is called unary that takes a single operand, an example of it is the Not operator.

 

Binary Operators:

It performs logical conjunction on two Boolean expression . For instance, if the expression is true and false the results is False ,if  the expression is true and true the results is True and if the expression is false or true the results is True.

example:

[vb] Dim name As String = “Kenjie”
Dim age As Integer = 12
If name = “Kenjie” And age = 12 Then
‘the statements return True
End If
If name = “Kenjie” Or age = 13 Then
‘the statements return True
End If
If name = “Kenjie” And age = 13 Then
‘the statements return False
End If
[/vb]

 

Unary Operators :

It performs logical negation on a Boolean expression. For instance, if the expression is true the results is true and if the expression is false the results is False

example

[vb] Dim name As String = “Kenjie”
Dim age As Integer = 12
If Not name = “Kenjie” Then
‘the statements return False
End If

If Not age = 13 Then
‘the statements return True
End If
[/vb]

 

 

 

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.