A more complex Boolean expression can be built of simpler Boolean expressions and can be written as
Boolean_Expression1 Logical Operator Boolean_Expression2
where
Boolean_Expression1andBoolean_Expression2can be any Boolean expressionLogical Operatorcan be one of those shown in the table that follows
PHP, Java, C++, C#
|
Logical Operator |
Description |
|
&& |
AND (also known as logical conjunction) |
|
|| |
OR (also known as logical disjunction) |
|
! |
NOT (also known as negation or logical complement) |
The truth table for all three operators is shown here.
|
Boolean Expression1 (BE1) |
Boolean Expression2 (BE2) |
|
|
|
|
False |
False |
False |
False |
True |
|
False |
True |
False |
True |
True |
|
True |
False |
False |
True |
False |
|
True |
True |
True |
True |
False |
Are you still confused? You shouldn’t be! It is quite simple!
- The result of the logical operator AND ( && ) is true when both BE1 and BE2 are
true. - The result of the logical operator OR ( || ) is true when either BE1 or BE2 is
true(at least one). - The logical operator NOT ( ! ) just reverses the result of a Boolean expression. In this table, when BE1 is
truethe result isfalseand vice versa.
Notice: In flowcharts, this website uses the commonly accepted AND, OR, and NOT operators!
Next are some examples of complex Boolean expressions. The parentheses are not really necessary. They are used just for increased readability.
(x == 5) && (x > y). This can be read as “test ifxis equal to 5 and greater thany”(x > y) || (x == 3). This can be read as “test ifxis greater than y or equal to 3”!(x < y). This can be read as “test ifxis not less thany” or, in other words, “test ifxis greater than or equal toy”
Notice: In the last Boolean expression, please note the exclamation mark in the front.
Visual Basic
|
Logical Operator |
Description |
|
And |
Also known as logical conjunction |
|
Or |
Also known as logical disjunction |
|
Not |
Also known as negation or logical complement |
The truth table for all three operators is shown here.
|
Boolean Expression1 (BE1) |
Boolean Expression2 (BE2) |
|
|
|
|
False |
False |
False |
False |
True |
|
False |
True |
False |
True |
True |
|
True |
False |
False |
True |
False |
|
True |
True |
True |
True |
False |
Are you still confused? You shouldn’t be! It is quite simple!
- The result of the logical operator
Andis true when both BE1 and BE2 aretrue. - The result of the logical operator
Oris true when either BE1 or BE2 istrue(at least one). - The logical operator
Notjust reverses the result of a Boolean expression. In this table, when BE1 istruethe result isfalseand vice versa.
Next are some examples of complex Boolean expressions. The parentheses are not really necessary. They are used just for increased readability.
(x = 5) And (x > y). This can be read as “test ifxis equal to 5 and greater thany”(x > y) Or (x = 3). This can be read as “test ifxis greater than y or equal to 3”Not(x < y). This can be read as “test ifxis not less thany” or, in other words, “test ifxis greater than or equal toy”
Python
|
Logical Operator |
Description |
|
and |
Also known as logical conjunction |
|
or |
Also known as logical disjunction |
|
not |
Also known as negation or logical complement |
The truth table for all three operators is shown here.
|
Boolean Expression1 (BE1) |
Boolean Expression2 (BE2) |
|
|
|
|
False |
False |
False |
False |
True |
|
False |
True |
False |
True |
True |
|
True |
False |
False |
True |
False |
|
True |
True |
True |
True |
False |
Are you still confused? You shouldn’t be! It is quite simple!
- The result of the logical operator
andis true when both BE1 and BE2 aretrue. - The result of the logical operator
oris true when either BE1 or BE2 istrue(at least one). - The logical operator
notjust reverses the result of a Boolean expression. In this table, when BE1 istruethe result isfalseand vice versa.
Next are some examples of complex Boolean expressions. The parentheses are not really necessary. They are used just for increased readability.
(x == 5) and (x > y). This can be read as “test ifxis equal to 5 and greater thany”(x > y) or (x == 3). This can be read as “test ifxis greater than y or equal to 3”not(x < y). This can be read as “test ifxis not less thany” or, in other words, “test ifxis greater than or equal toy”