Open the app
  1. Home
  2. Lessons
  3. KS3 Computing
  4. Block-based programming

Block-based programming

🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.

Block-based languages such as Scratch let you build programs by snapping blocks together. You cannot make spelling mistakes, so you can focus on the logic.

Events and sequence

A Scratch script starts with an event block, such as when green flag clicked or when this sprite clicked.
The blocks underneath run in order, top to bottom: that is sequence.
Motion blocks move a sprite: move (10) steps, turn (15) degrees.

Loops

repeat (10) runs the blocks inside it 10 times.
forever runs them again and again until the program is stopped.
To draw a square with the pen: repeat (4) { move (100) steps, turn (90) degrees }.
For any regular shape, the turn is 360 ÷ number of sides.

Decisions and variables

if < > then runs blocks only when a condition is true, for example: if touching edge then say Ouch!
Variables store data, such as a score. Blocks like change [score] by (1) update them.
ask [What is your name?] and wait gets input; the reply is stored in answer.
Worked example

A sprite should draw a regular pentagon (5 sides). What should go inside the repeat loop?

  1. A pentagon has 5 sides, so repeat (5).
  2. Turn = 360 ÷ 5 = 72 degrees.

Answer: repeat (5) { move (100) steps, turn (72) degrees }

Key idea

Scripts start with an event block. Blocks run in sequence; repeat and forever loop; if blocks make decisions. For a regular shape, turn 360 ÷ sides degrees.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.