Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · How computers work
How a program runs
set count to zerorepeat three times add oneshow count
Four instruction cards on the clothesline. The pushed-in card is inside the repeat.
The big ideaA computer follows a program one instruction at a time, very fast.

How it works

A program waits in memory until you press run. Then the processor reads one instruction, does it, and moves to the next.

A computer never guesses. It does only what is written, in the order written.

A missing line makes a bug, because the computer skips nothing and adds nothing.

A real processor does billions of tiny steps every second, but it still takes them one at a time, in order.

The programwaits inmemoryYou pressrunTheprocessorreads oneIt doeswhat itsaysIt moves tothe nextone
What happens when you press run.
Teo with his clipboard• one card at a time• a whole minute for four cardsA real processor• one instruction at a time• billions of tiny steps a second
Teo and a real processor.

Example 1: Run the cards

  1. The count starts at zero, and the loop adds one three times.
  2. 0 + 1 = 1, then 1 + 1 = 2, then 2 + 1 = 3.
  3. Then Teo reads the last card, show count, and the screen shows 3.

Example 2: Skip a card

  1. Teo skips one add one card, so only two adds happen.
  2. 0 + 1 + 1 = 2.
  3. Show count comes out as 2. A missing line makes a bug.
  4. Teo puts the card back, and the count shows 3 again.

Example 3: Two adds inside the loop

  1. Mr. Reyes puts two add one cards inside the repeat.
  2. Each of the three turns adds one twice.
  3. 3 * 2 = 6, so the screen shows 6.

Example 4: Jumping back

  1. At the repeat card, Teo jumps back to the start of the loop.
  2. He does the add one card, and the count goes up each time.
  3. When the repeats are used up, he moves on to the last card.

Words to know

program
A list of instructions.
memory
Where a program waits before it runs.
processor
Reads one instruction, does it, and moves on.
instruction
One card, one thing to do.
repeat
Jumps back to the start of the loop.

Watch out

Try it

  1. The count starts at zero, and the loop adds one three times. What does show count give?
  2. Where does a program wait before you press run?
  3. Teo skips one add one card out of three. What does show count give?
  4. Does a processor read all the cards at once?
  5. True or false: a computer guesses what you meant.
Answers: 1. 3 · 2. In memory · 3. 2 · 4. No, one at a time · 5. False
Try at homeAsk a grown-up to write four simple instructions on cards, like clap twice, turn around, touch your nose, sit down. Follow them one at a time, exactly as written. Then swap, and write them for the grown-up. Try writing one card badly, and see what the computer does.
For grown-upsPlay the Mission together: write four simple instructions on cards, like clap twice or touch your nose, and follow them one at a time, exactly as written. Then swap, and try one badly written card to see what the computer does.
Open these notes on screenScan the code, or go to tutorpip.com.