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.
What happens when you press run.Teo and a real processor.
Example 1: Run the cards
The count starts at zero, and the loop adds one three times.
0 + 1 = 1, then 1 + 1 = 2, then 2 + 1 = 3.
Then Teo reads the last card, show count, and the screen shows 3.
Example 2: Skip a card
Teo skips one add one card, so only two adds happen.
0 + 1 + 1 = 2.
Show count comes out as 2. A missing line makes a bug.
Teo puts the card back, and the count shows 3 again.
Example 3: Two adds inside the loop
Mr. Reyes puts two add one cards inside the repeat.
Each of the three turns adds one twice.
3 * 2 = 6, so the screen shows 6.
Example 4: Jumping back
At the repeat card, Teo jumps back to the start of the loop.
He does the add one card, and the count goes up each time.
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
A processor reads one instruction at a time. It does not read all the cards at once.
A computer does exactly what is written. It never guesses what you meant.
A computer skips nothing, so a missing line makes a bug.
A processor is very fast, but it still takes the steps in order.
Try it
The count starts at zero, and the loop adds one three times. What does show count give?
Where does a program wait before you press run?
Teo skips one add one card out of three. What does show count give?
Does a processor read all the cards at once?
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.