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_Expression1 and Boolean_Expression2 can be any Boolean expression
  • Logical Operator can 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)

BE1 && BE2

BE1 || BE2

!(BE1)

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 true the result is false and 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 if x is equal to 5 and greater than y
  • (x > y) || (x == 3). This can be read as “test if x is greater than y or equal to 3
  • !(x < y). This can be read as “test if x is not less than y” or, in other words, “test if x is greater than or equal to y

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)

BE1 And BE2

BE1 Or BE2

Not(BE1)

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 true the result is false and 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 if x is equal to 5 and greater than y
  • (x > y) Or (x = 3). This can be read as “test if x is greater than y or equal to 3
  • Not(x < y). This can be read as “test if x is not less than y” or, in other words, “test if x is greater than or equal to y

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)

BE1 and BE2

BE1 or BE2

not(BE1)

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 true the result is false and 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 if x is equal to 5 and greater than y
  • (x > y) or (x == 3). This can be read as “test if x is greater than y or equal to 3
  • not(x < y). This can be read as “test if x is not less than y” or, in other words, “test if x is greater than or equal to y

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!