Sign in

← All revision topics

English variety

Block programming: sequences and loops

Machine translation

Around age 8 · Usually taught in ⁨Key Stage 2⁩ · Free

Learn

  1. A program is an algorithm written for a computer or a robot to follow. In block programming, each block is an instruction.

    move forward
    move forward
    turn right
    move forward
    A program made of four blocks
  2. The blocks go one below another. The robot follows them from top to bottom, one after another. That is a sequence. If you change the order, the robot may end up somewhere else.

    The robot is facing one way. “Move forward” moves it 1 square in the direction it is facing. “Turn right” only changes the direction it is facing. It does not move it to another square.

    S
    It starts facing up: move forward 2, turn right and move forward 1
  3. If you have to do the same thing many times, do not write lots of identical blocks. Use a loop. A loop repeats blocks. “Repeat 3 times” does what is inside 3 times. What is inside goes a little further to the right. This is called indentation.

    Without a loop:
    move forward
    move forward
    move forward
    move forward
    With a loop:
    repeat 4 times
    move forward
    Both programs do the same thing
  4. Loops are also useful for counting. “Repeat 3 times: put down a basket with 2 bread rolls” puts down 3 baskets. In total there are 6 bread rolls.

    3 baskets with 2 bread rolls in each

Worked examples

Example 1

Gus programs a robot. It starts at the bottom left, facing up. Its program is: move forward, turn right, move forward, move forward. Where does it end up?

S
  1. Move forward: go up 1 square.
  2. Turn right: it now faces right, but it stays in the same square.
  3. Move forward twice: it moves 2 squares to the right.

It ends up 1 square up and 2 to the right of the start.

Watch out! Many people here think that turning right moves the robot 1 square.

Common mistake

Example 2

Julie writes this program: repeat 3 times, move forward and turn left. How many times does the robot move forward? How many times does it turn?

repeat 3 times
move forward
turn left
  1. What is inside the loop is move forward and turn left.
  2. The loop repeats it 3 times.
  3. It moves forward 3 times and turns 3 times.

It moves forward 3 times and turns 3 times.

Watch out! Many people here say it moves forward 1 time, because they see only 1 “move forward” block.

Common mistake

Example 3

Tony writes four “move forward” blocks in a row. How can he write it with a loop?

move forward
move forward
move forward
move forward
  1. Look at which block repeats: move forward.
  2. Count how many times it repeats: 4.
  3. Write “repeat 4 times” and put “move forward” inside it, with indentation.

Repeat 4 times, and inside: move forward.

Watch out! Here lots of people write “repeat 4 times” and leave “move forward” outside, without indentation.

Common mistake

A challenge to think about

On a piece of paper, write a program with blocks so that a friend walks once around a chair. Use a loop so you don't repeat the blocks. Your friend acts as the robot and only does what the paper says. Do they get there?

Practise

Rounds of 10 questions. Choose a level:

Your grade in this topic:No grade yetDo a round at the Basic level to get a grade.

Next topic: Conditionals and variables in block-based programming →