The 3 logical or Boolean operators are:
The logical operators, AND, OR and NOT can be used to combine expressions that are linked in some way.
They are sometimes called Boolean operators, after the mathematician George Boole.
Boolean logic works with statements that are either true or false, and then considers how such statements might be combined using simple operators, most commonly AND, OR and NOT.
In Boolean logic:
● A AND B is true if both statement A is true AND statement B is true, otherwise it’s false
● A OR B is true if statement A is true OR if statement B is true OR if both statements A and B are true
● NOT A is true if statement A is false (NOT true)
We will look at some examples to help you to understand how logical operators are used to write computer programs.
The 3 logical or Boolean operators are:
The logical operators, AND, OR and NOT can be used to combine expressions that are linked in some way.
They are sometimes called Boolean operators, after the mathematician George Boole.
Boolean logic works with statements that are either true or false, and then considers how such statements might be combined using simple operators, most commonly AND, OR and NOT.
In Boolean logic:
● A AND B is true if both statement A is true AND statement B is true, otherwise it’s false
● A OR B is true if ststement A is true OR if statement B is true OR if both statements A and B are true
● NOT A is true if statement A is false (NOT true)
We will look at some examples to help you to understand how logical operators are used to write computer programs.
First, watch the videos below to learn how these logical operators can be used.
One very important use for logical operators is to extract information from a database.
A question or query which extracts data to meet a number of different criteria can be built up using a series of logical operators.
E.g. Find all of the children who are girls AND over 7 years old but who do NOT play for the netball team.
SQL, or Structured Query Language is a whole language dedicated to processing data in this way.
Complete the search task below this database table.
34. List all employees who are female AND live in Mumbai but do NOT work in HR.
35. List all employees who's age is > than 28 AND do NOT work in IT.
In an archery game the bow must fire an arrow at an angle between 8 degrees and 14 degrees to hit the target.
n is the variable used to store the angle of the bow.
The script for this game combines comparators with logical operators to find out if the angle stored in the variable n is greater than 8 AND less than 14.
The script below will tell the user when the arrow is on target.
An app has been created to help children to improve their nutrition.
It asks the children which of the foods shown above will give them energy.
The correct answers are pasta or rice.
The script below is used to check their answer.
NOT can be used to eliminate all the things you do NOT want.
A smart farm gate is being used to sort sheep from other farm animals.
The gate is programmed so that if the animal is NOT a sheep the gate will stay closed.
Q36. What are the three Boolean operators?
Q37. Who were they named after?
Testing your understanding.
Study the diagram below and use it to answer questions 27 to 29.
Q38. List the numbers in the diagram that are Greater than 10 OR Less than 20.
Q39. List the numbers in the diagram that are Less than 20 AND Greater then 10.
Q40. List the numbers in the diagram that are NOT Greater than 10.