Learning Intention

  • I can refine a program by using a repeat instruction

Introduction

The repeat instruction on the Control palette

What did we learn to do in the previous session? (Use the keyboard to control Picoh.) Remember that when we use the keyboard, Picoh's head will only continue to move up and down as long as the N key is being pressed. Consequently, if you press N again and again, Picoh will nod again and again. However, in programming this is not the most efficient way to perform an instruction multiple times. Look at the Control palette — can you see an instruction that could help us? We need to use the `repeat` instruction. This week we will learn to write code using repeat.

Teacher Input

Ask the children to open the Picoh application and go to New on the File menu to create a blank program. Let's see if we can find `repeat`. Go to the Control palette and drag out a `repeat` instruction. Demonstrate that the number can be changed to set how many times the code inside the loop is repeated. Can you write some code to make Picoh's head move up and down 10 times? How many times do you need to repeat the code? (10.)

Activities

1.

Write a program to make Picoh's head move up and down 10 times. File, Save As - headnodwithrepeat

Code repeating a head nod ten times
2.

Can you write a program that will make Picoh shake its head twice and then look straight ahead? File, Save As - crossingtheroad

Code shaking Picoh's head twice
3.

Can you write some code for Picoh to perform a sequence of movements one after the other? E.g. nod twice, shake twice then blink twice. File, Save As - keepfit

Code performing a keep fit sequence

Extension

Can you write your own keep fit sequence for Picoh with at least 3 moves and using repeat? File, Save As - mykeepfit

Plenary

How did you find today's lesson? (Thumbs up, down, middle). Remember that programmers can be quite lazy, so repeats are perfect for them because they mean shorter programs and less work.

Ohbot image

Key Points

  • `repeat` (Control palette) runs the instructions inside it a set number of times.
  • Changing the number changes how many times the loop runs.
  • A repeat is shorter and clearer than copying the same blocks over and over.
  • Repeats can be combined in sequence to build longer routines.

Need Help?

If you're stuck on any part of this lesson, check out these resources:

Ohbot