Visual Basic 2008 9.0 .NET Examples and Ebook
  Home

Introduction to Visual Basic

Arrays

Volgend Onderwerp

Logical Disjunction Operator Xor

Vorig Onderwerp

Boolean Logical

|

Logical Shortcircuit Operators AndAlso and OrElse

Volgend Onderwerp
-


An "exclusive or" operator Xor exists. A combination of two Boolean expressions with this operator will only result in True when exactly one of the two combined expressions is True :


 condition-1   condition-2     condition-1 Xor condition-2
 False         False           False
 False         True            True
 True          False           True
 True          True            False

Suppose we need to give the sum of two entered values only if exactly one of the two values is positive ( above zero ).


Module Examplel
    Sub Main()
        Console.WriteLine("Value 1 ?")
        Dim value1 As Integer = Console.ReadLine()
        '
        Console.WriteLine("Value 2 ?")
        Dim value2 As Integer = Console.ReadLine()
        '
        If value1 > 0 Xor value2 > 0 Then
            Console.WriteLine("Sum : " & (value1 + value2))
        End If
        '
        Console.ReadLine()
    End Sub
End Module
Download Broncode

Output :

 Value 1 ?
 5
 Value 2 ?
 -10
 Sum : -5

Output :

 Value 1 ?
 -5
 Value 2 ?
 10
 Sum : 5

Output :

 Value 1 ?
 5
 Value 2 ?
 10

Output :

 Value 1 ?
 -5
 Value 2 ?
 -10

Updated On : 2008-11-06

Download Broncode

Published On : 2008-11-06

Logical Disjunction Operator Xor

Vorig Onderwerp

Boolean Logical

|

Logical Shortcircuit Operators AndAlso and OrElse

Volgend Onderwerp

Introduction to Visual Basic

Arrays

Volgend Onderwerp
  Home  
Nederlands
Nederlands

Add to favorites (IE).


No printable version available.