KS3National Curriculum Y7.2 24 min read 10 question quiz 16 exam marks

Programming Essentials in Scratch

Sequence, selection and iteration using blocks, plus variables and events. Everything you learn here transfers directly to Python.

Sequence

A sequence is a set of instructions carried out in order, one after another.

Computers are extremely literal. They do exactly what you say, in exactly the order you say it, which is why a program that seems obviously correct can still do something ridiculous.

when green flag clicked say "Hello!" for 2 seconds move 100 steps turn 90 degrees move 100 steps

Swap two of those blocks and the sprite ends up somewhere completely different.

Order is part of the instruction

Putting the right steps in the wrong order is just as wrong as having the wrong steps.

Three block scripts: a sequence, a selection and a repeat loop, each with what it does on the stageThree scripts built from coloured blocks, each starting with a yellow when flag clicked block, which is an event. Sequence: the blocks run from top to bottom, move 80 steps, turn right 90 degrees, move 80 steps, say Hello, and the sprite walks right, turns and walks down. Selection: an if else block chooses one path from a condition. If touching edge then turn 180 degrees, else move 10 steps, and only one of the two paths runs. Iteration: a repeat 4 block runs the blocks inside it four times, move 80 steps and turn right 90 degrees, which draws a square with four equal sides.Sequence1when flag clickedmove80stepsturn right90degreesmove80stepssayHello!Hello!one block after another,in the order they are stackedSelection2when flag clickediftouching edge?thenelseturn180degreesmove10stepsthe condition picks one path.only one of them runsIteration3when flag clickedrepeat4move80stepsturn right901234repeat does the same stepsagain: four sides, four timesAn event, such as the green flag being clicked, starts every script.
  1. Sequence: the blocks run one after another from the top, in the order they are stacked.
  2. Selection: the if block asks a question and picks one of two paths. Only one path runs.
  3. Iteration: repeat runs the blocks inside it again and again. Four sides, four identical steps, so repeat 4.
Every program is built from these three ideas: sequence, selection and iteration.

Selection and variables

Selection

Selection means the program chooses what to do based on a condition.

if <touching edge?> then turn 180 degrees

if <score > 10> then say "You win!" else say "Keep going"

The if ... else block gives two paths. Only one of them runs.

Conditions

A condition is a question with a yes or no answer:

  • touching edge?
  • key space pressed?
  • score > 10
  • answer = "blue"

Variables

A variable is a named box that stores a value which can change while the program runs.

set score to 0 change score by 1 set lives to 3 change lives by -1

Common uses: score, lives, timer, player name, level number.

Set your variables at the start

If you do not set score to 0 when the green flag is clicked, the score carries over from the last time you played, which is one of the most common bugs in Scratch projects.

Iteration and events

Iteration

Iteration means repeating instructions. Scratch has three loop blocks.

BlockWhat it does
repeat 10Runs exactly 10 times, a count controlled loop
foreverRuns until the program is stopped
repeat until <condition>Runs until the condition becomes true

Drawing a square:

repeat 4 move 100 steps turn 90 degrees

Four sides, four identical steps. Writing it out four times would work, but the loop is shorter, clearer and easier to change into a pentagon.

Events

An event starts a script when something happens.

  • when green flag clicked
  • when space key pressed
  • when this sprite clicked
  • when I receive [message]

Broadcasting lets one sprite tell another sprite to do something, which is how sprites work together in a game.

Debugging

When a Scratch program does not work:

  1. Check the order of the blocks
  2. Check every variable is set at the start
  3. Check the condition is the right way round, for example > where you meant <
  4. Check the script is attached to the right sprite
  5. Click blocks individually to see what each one actually does
Sequence, selection and iteration as Scratch blocksEvery program is built from three constructs. Sequence means the instructions run in order from top to bottom, so a script might say hello, move ten steps and then turn fifteen degrees. Selection means the program chooses between paths using if and else, so if the sprite is touching the edge it turns around and says ouch, and otherwise it keeps moving, with only one branch ever running. Iteration means a block of instructions repeats, so repeat ten times around a move of ten steps and a turn of thirty six degrees draws a complete circle.The three things every program is built fromwhen green flag clickedsay Hello!move 10 stepsturn 15 degreesruns inthis orderif touching edge? thenturn 180 degreessay Ouch!elsemove 10 stepsonly onebranch runsrepeat 10move 10 stepsturn 36 degreesthese two runten timesten moves and ten turns of 36 degrees draws a circle
These three ideas are the whole of programming. Everything you write later in Python is still only these, in different words.

Key terms you must be able to define

Algorithm
A set of step by step instructions for solving a problem.
Sequence
Instructions carried out one after another in order.
Selection
Choosing what to do based on whether a condition is true.
Iteration
Repeating a set of instructions.
Variable
A named store for a value that can change while the program runs.
Condition
A question with a true or false answer, used to make a decision.
Event
Something that happens, such as a key press, that starts a script.
Sprite
An object in Scratch that can be moved, costumed and given its own scripts.
Broadcast
A message one sprite sends so that other sprites can respond.
Debugging
Finding and fixing errors in a program.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineAlgorithm
AnswerA set of step by step instructions for solving a problem.
DefineSequence
AnswerInstructions carried out one after another in order.
DefineSelection
AnswerChoosing what to do based on whether a condition is true.
DefineIteration
AnswerRepeating a set of instructions.
DefineVariable
AnswerA named store for a value that can change while the program runs.
DefineCondition
AnswerA question with a true or false answer, used to make a decision.
DefineEvent
AnswerSomething that happens, such as a key press, that starts a script.
DefineSprite
AnswerAn object in Scratch that can be moved, costumed and given its own scripts.

Reach the top grade on this topic

The top level at Key Stage 3 is about explaining choices, not just making things work.

Say which construct you used and why. "I used a repeat until loop rather than a repeat 10 loop, because the player might reach the target at any time and I do not know how many attempts they will need."

Predict before you run. Read a script and say what it will do before clicking the green flag. Being able to predict is what shows you understand it rather than having got there by trial and error.

Debug systematically. Do not just move blocks around until it works. Say what you expected, what actually happened, and what that difference tells you about where the fault is.

  • Explain the difference between repeat, forever and repeat until, with an example use for each
  • Predict the output of a script containing a loop and an if block
  • Explain why a variable must be reset at the start of a game
  • Find and describe a fault in a given script

Mistakes that cost marks here

Avoid these
  • Forgetting to set variables back to their starting value when the green flag is clicked.
  • Using forever when the loop needs to stop, so the rest of the script never runs.
  • Attaching a script to the wrong sprite and then wondering why nothing happens.
  • Putting the if block outside the loop when it needs to be checked on every repeat.
  • Getting a condition the wrong way round, such as using less than when greater than was meant.
Fun fact

Scratch was made at MIT and released in 2007. It now has over 100 million registered projects, which makes it one of the largest collections of programs ever written by children anywhere in the world.

Knowledge check

0 of 10 answered
1Which construct means repeating instructions?
2What does repeat until <touching edge?> do?
3Why should a score variable be set to 0 when the green flag is clicked?
4Which blocks would draw a triangle?
5What is an event in Scratch?
6Which condition would check that a player has more than 5 lives?
7What does broadcasting allow you to do?
8A sprite should bounce when it hits the edge. Which construct is needed?
9What is debugging?
10Which loop should be used when you do not know how many repetitions are needed?
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

16 marks
1State what is meant by sequence, selection and iteration.3 marks
State

Mark scheme0 / 3
  • LSequence is instructions carried out in order one after another
  • LSelection is choosing what to do based on a condition
  • LIteration is repeating instructions
Model answer

Sequence means carrying out instructions one after another in the order they are written. Selection means the program chooses between different paths depending on whether a condition is true or false, using an if block. Iteration means repeating a set of instructions, either a fixed number of times or until a condition is met.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain why a variable is useful in a game, giving an example.3 marks
Explain

Mark scheme0 / 3
  • LA variable stores a value that can change while the program runs
  • LGives a valid example such as score, lives or a timer
  • LExplains how it is used, such as increasing the score when a target is hit
Model answer

A variable is a named store that holds a value which can change while the program is running, which is exactly what a game needs to keep track of what is happening. For example, a score variable would be set to 0 when the green flag is clicked, and then changed by 1 every time the player catches a falling object. The current value can then be checked in a condition, so the game can end or move to the next level when the score reaches a target.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3A student's Scratch game keeps the score from the previous game when it is restarted. Explain the cause of this problem and how to fix it.3 marks
Explain

Mark scheme0 / 3
  • LVariables keep their value between runs
  • LThe score is never set back to zero when the game starts
  • LFix by adding a set score to 0 block after the green flag is clicked
Model answer

The cause is that a variable keeps whatever value it was last given, and that value is remembered even after the program stops. Because the student's script never sets the score back to zero, the new game simply continues from the value left over at the end of the previous one. The fix is to add a set score to 0 block immediately after the when green flag clicked block, so that the score is reset every time a new game begins.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Describe how you would use a repeat block to draw a square, and explain why using a loop is better than repeating the blocks four times.4 marks
Describe

Mark scheme0 / 4
  • LUses a repeat 4 block
  • LContains a move block and a turn 90 degrees block
  • LA loop means less code to write and read
  • LIt is easier to change, for example altering the size or number of sides in one place
Model answer

To draw a square you would use a repeat 4 block containing a move 100 steps block followed by a turn 90 degrees block. Each pass draws one side and turns the corner, and after four passes the sprite has turned through 360 degrees and returned to where it started. Using a loop is better than writing the two blocks out four times because the script is much shorter and easier to read, and more importantly it is far easier to change. If you wanted a larger square you would only have to edit one move block instead of four, and if you wanted a different shape you would only have to change the repeat number and the turn angle.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5A game should say 'Well done' when the score reaches 10, and 'Keep trying' otherwise. Write the blocks you would use.3 marks
Write

Mark scheme0 / 3
  • LUses an if else block
  • LCondition tests whether the score is 10 or more
  • LCorrect message in each branch
Model answer

if <score > 9> then say "Well done" else say "Keep trying" The if else block gives two paths and only one of them runs. The condition checks whether the score has reached 10, and because Scratch has a greater than block rather than a greater than or equal to block, testing for greater than 9 is the usual way to include 10 itself.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 16