KS3 Computing · An algorithm is a precise, step-by-step plan to solve a problem. Computational thinking turns a messy problem into one. Every algorithm is built from just three things: sequence, selection and iteration.
Use PRIMM to read a script: predict what it does before running it.
Identify the block where a buggy script first goes wrong.
Fix a bug, test it again, and explain the fix in one sentence.
Success criteria
I can write my prediction down before I click the green flag.
I can find and fix the bug in three buggy scripts.
I can explain each fix in one clear sentence.
Key words
Say each word, then read what it means. Every one is in the glossary too.
Algorithm
Precise, ordered, finite steps to solve a problem.
Decomposition
Breaking a problem into smaller ones.
Abstraction
Ignoring detail that doesn't matter for the problem.
Sequence · selection · iteration
Steps one after another. First this, then this.
Pseudocode
Code-like writing for algorithms, without strict rules.
Trace table
Records variable values step by step to check logic.
Variable
A named place in memory that holds a value.
The explanation
Read it here, or open the study page below to go one step at a time with things to try.
Bugs are normal
A bug is a mistake in a program that makes it do the wrong thing.
Debugging means finding bugs and fixing them.
Every programmer writes bugs. Good programmers find them calmly, one step at a time.
★Remember
Scratch blocks only snap together where they fit. So most Scratch bugs are logic errors: the script runs, but does the wrong thing.
PRIMM: a way to read code
PRIMM is five steps for working with a program someone else wrote.
Letter
Step
What you do
P
Predict
Read the code. Say what you think it will do, before you run it.
R
Run
Run it and watch. Was your prediction right?
I
Investigate
Look closely. Trace it block by block. Change one thing and see what happens.
M
Modify
Change the code so it does something new.
M
Make
Write your own program using the same idea.
?Why?
Why predict first?
A wrong prediction is useful. The place where the code surprises you is where to look for the bug.
Debugging step by step
Predict: what should the script do?
Run it.
Compare: what did it really do? Where is it different?
Find the first block where it goes wrong.
Fix one thing at a time.
Run it again to check the fix works.
Explain the fix in one sentence.
!Watch out
Change only one thing, then test. Change three things at once and you will not know which one fixed it.
Common Scratch bugs
Bug
What you see
Fix
Variable never reset
The score starts at the last game's number
Put set [score v] to (0) under when green flag clicked
Wrong sign
Lives go up instead of down
Use change [lives v] by (-1)
Missing loop
The sprite moves once, then stops
Put the blocks inside forever or repeat
Wrong number
Repeat 3 with turn 90 draws only three sides of a square
Use repeat (4)
Blocks in the wrong order
The sprite says 'Done!' before it moves
Drag the say block below the move blocks
Script on the wrong sprite
The wrong sprite moves
Drag the script onto the right sprite
e.g.Worked example
This script should count lives down from 3 and then say 'Game over'. It never says it. Why? Script: set lives to 3. Repeat until lives = 0: wait 1 second, change lives by 1. Say Game over.
Predict: lives should go 3, 2, 1, 0, then the sprite says 'Game over'.
Run: lives go 4, 5, 6, 7 … and never stop.
Compare: lives go up, not down, so they never reach 0.
Find: the block change [lives v] by (1) adds 1.
Fix: change it to change [lives v] by (-1) and run it again.
Explain: 'The loop never ended because lives went up, so they never reached 0.'