work with operators

oka

New member
Joined
Jul 14, 2006
Messages
3
Programming Experience
Beginner
VB.NET:
Module Module1

    Sub Main()

        Dim x As Integer = 2
        Dim y As Integer = 5
        Dim z As Integer = 6
        Dim answer As Integer
        answer = (x * y) + z
        Console.WriteLine(answer)

        Dim a As Boolean = True
        Dim b As Boolean = False
        Dim answer2 As Boolean
        answer2 = a Or b
        Console.WriteLine(answer2)

        If (b Or (z < 5 And answer > 20)) Then
            Console.WriteLine("Conditional returned True.")
        Else
            Console.WriteLine("Conditional returned False.")
        End If

        Console.ReadLine() 'wait for user to press enter

    End Sub

End Module
the program shows output as

VB.NET:
16
True
Conditional returned False.
Can anybody tell, how does "True" come in the second line of the output?
 
Because you wrote it there with answer2. Or operator returns True if either expression is True. It is the inclusive logical disjunction of two Boolean values, as they say in documentation. Nice chart there too: http://msdn2.microsoft.com/en-us/library/06s37a7f.aspx
 
Back
Top