LightMySky

Conditions That Combine: And, Or and Not

One test is often not enough. Joining tests with and, or and not lets a single decision depend on several things at once, and each joiner changes when the branch is taken.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Write a condition true only when two things hold at once, and one true when either holds
  • Say what not turns each of those into, with a case that shows the difference
  • Find the case that breaks a condition that used or where it needed and

1 · Read

One test is often not enough. Joining tests with and means every part must be true. Joining with or means at least one part must be true.

Try it together

You want a bonus level when the score is over ten and the timer has not run out. With a score of 12 and time left, both parts hold, so the level opens. With a score of 12 but no time left, one part fails, so it stays shut.

The word not flips any test to its opposite. Saying not hungry is true exactly when hungry is false. So not in front of a joined test flips the whole result, and you can check this with one case at a time.

The classic bug is writing or where you needed and. Test it with a case where only one part holds. If the branch is taken when it should not be, swap or for and.

And needs every part true, or needs just one true part, not flips a test, so try a case where only one part holds to catch an or where you needed and.

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Where this leads

Jobs that lean on this skill. Follow one to see everything it is built on.

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Conditions That Combine: And, Or and Not · Computing, ages 12 to 13 · LightMySky