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 choice —
IF, and the questions=,<and>. - One or the other —
ELSE, and a chain of questions with one answer. - A yes you can keep —
TRUEandFALSEas values, and the flag that carries an answer from where it was found to where it is needed. - Asking two things at once —
AND,ORandNOT, 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.