Skip to content
IGCSE·Tuition
Computer Science · Lessons

Evaluate a logical expression with parentheses

A Boolean expression looks short, yet one misplaced bracket can flip the whole answer.

On this page
  1. What do the three operators do?
  2. How to evaluate step by step
  3. Worked example
  4. The mistake to watch for
  5. Check yourself
  6. Where this leads next

To evaluate a Boolean expression, replace each letter with its value (1 for true, 0 for false) and work out the operators in a fixed order: brackets first, then NOT, then AND, then OR. Every step produces another 1 or 0, so a long expression is just a short chain of small decisions.

This skill sits at the start of the Boolean logic module. It supports truth tables, circuits and the conditions you write in your own algorithms.

What do the three operators do?

  • NOT flips a value: NOT 1 = 0 and NOT 0 = 1.
  • AND gives 1 only when both inputs are 1.
  • OR gives 1 when at least one input is 1.

In Cambridge-style pseudocode these are written as the words NOT, AND and OR. The same idea inside a condition looks like this:

IF (Age >= 13) AND NOT (HasConsent) THEN
   OUTPUT "Ask a parent first"
ENDIF

How to evaluate step by step

  1. Substitute the value for every letter and write it under the letter.
  2. Work out every bracket, innermost first.
  3. Apply NOT to the single value or bracket directly after it.
  4. Apply AND from left to right.
  5. Apply OR last. The final 1 or 0 is the answer.

Worked example

Find Q = (A OR B) AND NOT C when A = 0, B = 1 and C = 0.

Step 1, substitute: (0 OR 1) AND NOT 0.

Step 2, bracket: 0 OR 1 = 1, so the expression is 1 AND NOT 0.

Step 3, NOT: NOT 0 = 1, so the expression is 1 AND 1.

Step 4, AND: 1 AND 1 = 1.

Q = 1. Now change C to 1 and repeat: (0 OR 1) AND NOT 1 = 1 AND 0 = 0. One input changes, the output changes, and the same steps apply.

The mistake to watch for

Students sometimes ignore the operator order and read from left to right. Take A = 1, B = 0, C = 0 and the expression A OR B AND C with no brackets.

Mistaken working: (1 OR 0) AND 0 = 1 AND 0 = 0.

AND comes before OR, so the correct working is 1 OR (0 AND 0) = 1 OR 0 = 1. If the question really had brackets, (A OR B) AND C, then the answer would be 0. The brackets decide the answer, so copy them exactly and never move them.

You can test your reasoning in Python, where a or b and c follows the same order. The restricted pseudocode trace trainer and the safe Python reasoning sandbox are useful for checking small cases.

Check yourself

1. Find NOT (X AND Y) when X = 1 and Y = 1.

Show answer

Bracket first: 1 AND 1 = 1. Then NOT 1 = 0.

2. Find (P OR Q) AND NOT R when P = 0, Q = 1 and R = 1.

Show answer

(0 OR 1) = 1. NOT 1 = 0. Then 1 AND 0 = 0.

3. Find NOT A OR B AND C when A = 0, B = 1 and C = 0 (no brackets).

Show answer

NOT first: NOT 0 = 1. AND next: 1 AND 0 = 0. OR last: 1 OR 0 = 1.

Where this leads next

Once evaluation is automatic, move on to constructing a truth table, where you evaluate the same expression for every possible input. Then try the Boolean logic practice set. The Boolean and number-representation lab lets you test small expressions of your own.

If a Boolean answer still goes wrong although each rule makes sense, a teacher can trace the slip with you. That is the focus of our online one-to-one Computer Science tuition.

Questions people ask

Which is evaluated first, AND or OR?

AND is evaluated before OR, and NOT is evaluated before both. Brackets override everything, so the part inside brackets is always worked out first. When you are unsure, add brackets yourself to make the order visible, because a clearly bracketed expression leaves no room for a second reading.

Does NOT apply to the whole expression or just the next value?

NOT applies only to the single value or bracketed group directly after it. In NOT A AND B, only A is inverted. In NOT (A AND B), the whole bracket is worked out first and then inverted. These two give different answers for some inputs.

Do I need to learn Python for Boolean logic?

No. Exam answers use pseudocode and logic notation. Python is useful only as a way to test your own reasoning, because the keywords and, or and not follow the same order as AND, OR and NOT in pseudocode.

Sources

  1. Cambridge IGCSE Computer Science 0478 syllabus page

Updated:

Your next step

If you can follow the order of evaluation in class but still lose the answer in longer expressions, a one-to-one teacher can watch your working line by line and find the exact step that slips.

Paid one-hour trial at your assigned teacher’s confirmed rate, starting from RM80. Other fees, schedules and ongoing arrangements are confirmed directly with your teacher after the trial class.

Tuition is arranged with a parent or guardian. Send them this page on WhatsApp and they can enquire for you.

Parent or guardian? Enquire here

9,000+ students helped through our service