Skip to content

Foundations

Decisions

A program that reacts: test a value, choose between paths, keep a yes or no in a box, and join questions together.

Begin — Unit 01 →

What this is

Everything before this runs the same way every time, whatever the values are. This is where a program learns to decide: to ask a question, and do something only when the answer is yes.

Four units take that from a single test to a chain of them, to keeping an answer in a box for later, to joining questions so one test can ask about several things at once.

Who it’s for

Anyone who has finished Working It Out. The questions a program asks are comparisons between values, so you need to be comfortable with values first.

The shape

  • Making a choiceIF, and the questions =, < and >.
  • One or the otherELSE, and a chain of questions with one answer.
  • A yes you can keepTRUE and FALSE as values, and the flag that carries an answer from where it was found to where it is needed.
  • Asking two things at onceAND, OR and NOT, and brackets that say what to work out first.

Next comes Repeating. If your tests are getting tangled, Truth Tables is a short side-path from here that shows you how to be sure what a test does.

The units

  1. 01Making a ChoiceStart →
  2. 02One or the OtherStart →
  3. 03A Yes You Can KeepStart →
  4. 04Asking Two Things at OnceStart →