g_johnson
asked on
I have a VB.Net assignment statement with an or clause. What does it mean?
VB.Net
dim a as Boolean = false
dim b as Boolean = true
dim c as Boolean
This line of code confuses me:
c = a or b
I've never seen a line of code like that. What does it mean?
My best guess is that it means if a is null then set c to equal b, but that's truly a wild guess. Is this even a valid line of code?
dim a as Boolean = false
dim b as Boolean = true
dim c as Boolean
This line of code confuses me:
c = a or b
I've never seen a line of code like that. What does it mean?
My best guess is that it means if a is null then set c to equal b, but that's truly a wild guess. Is this even a valid line of code?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>So, I think you are saying that if either a or b is true, c will be true. Is that correct?
correct
>>The only way c is false is if both a and b are false. Still correct?
False. If a OR b is false, c is set to false.
correct
>>The only way c is false is if both a and b are false. Still correct?
False. If a OR b is false, c is set to false.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This all stems from a bitwise operation whereas 0 = False and 1 = True. So changing our program we can prove at the bit level that the boolean operation is correct:
Module Module1
Sub Main()
Console.WriteLine("Let's test Or")
OrTest(1, 1)
OrTest(0, 1)
OrTest(1, 0)
OrTest(0, 0)
Console.WriteLine()
Console.WriteLine("Now let's test And")
AndTest(1, 1)
AndTest(0, 1)
AndTest(1, 0)
AndTest(0, 0)
Console.ReadLine()
End Sub
Sub OrTest(ByVal lhs As Short, ByVal rhs As Short)
Console.WriteLine("{0} OR {1} = {2}", lhs, rhs, lhs Or rhs)
End Sub
Sub AndTest(ByVal lhs As Short, ByVal rhs As Short)
Console.WriteLine("{0} AND {1} = {2}", lhs, rhs, lhs And rhs)
End Sub
End Module
Which now produces the following output --saige-
ASKER
Thanks, all!
ASKER
The only way c is false is if both a and b are false. Still correct?
Thanks!