boolean logic logical operators comparison operators truth tables
TRANSCRIPT
Boolean Logic
Logical Operators
Comparison Operators
Truth tables
Boolean Logic
• The Boolean values (named after mathematician George Boole)
are TRUE and FALSE.• They can be established in a number of
ways:– Assertion– Boolean Expression– Comparison
Assertion
To assert means to state.
VB example:
Dim Flag As Boolean
Flag = True
Boolean Expression
Logical operators can be used to construct Boolean expressions from Boolean values.
The operands (arguments) must be Boolean.
Not unary, prefix
And dyadic, infix
Or dyadic, infix
Xor dyadic, infix
NOT
Dim Flag As Boolean
Flag = True
Flag = Not Flag
AND
Dim IsNiceWeather As BooleanDim HaveMoney As BooleanDim GoSkiing As BooleanGoSkiing = IsNiceWeather And HaveMoney
OR
Dim GoodBand As Boolean
Dim HotDate As Boolean
Dim GoOut As Boolean
GoOut = GoodBand Or HotDate
XOR
Dim Cookie As Boolean
Dim Candy As Boolean
Dim MomSays As Boolean
MomSays = Cookie Xor Candy
Comparison (= <> <= >= > <)
Comparison Operators are used to establish relationships between Boolean values.
All operators are dyadic, infix.Their arguments can be of any data type, but
must be similar, i.e. both Boolean,both numeric,both String.
Comparison (= <> <= >= > <)
Dim X As Double
Dim Y As Integer
Dim Name1 As String
Dim Name2 As String
Dim Result As Boolean
Result = Name1 < Name2
Result = X = Y
Arithmetic Operators(review)
• exponentiation• multiplication• division (real)• division (integer quotient)• division (integer remainder) • addition• Subtraction
^
*
/
\
Mod
+
-
Other Operators (in order of precedence)
Concatenation &, +
Comparison = <> <= >= > <
Logical Not
And
Or
Xor
Assignment =