Foundations
Repeating
Three kinds of loop: a set number of times, until something happens, and only while something holds. The second one is the shape of every game.
Begin — Unit 01 →What this is
Computers exist so that you never have to write the same line ten times. A loop does a piece of work over and over, and you write the work once.
There are three ways to say how many times, and this module takes them in turn. By the end of the second one you will have turned the guessing game from Decisions into something you can play.
Who it’s for
Anyone who has finished Decisions. Two of the three loops leave when a question comes back a certain way, so you need to be able to write the question.
The shape
- Doing it again — the counted loop, and a counter you can use as it goes.
- Until you get it — the loop that runs until something happens,
RANDOM, and the game loop at the heart of every game. - Checking before you start — the loop that asks first, so the work can happen no times at all.
Next comes Structure, where a box holds many values and a job gets a name.