Sequence 1 - Lesson 3: Over and Over
Learning Intention
I can refine a program by using the repeat instruction.
I can refine a program by using the repeat instruction.
Introduction
What did we learn to do in the previous session? (Use the keyboard to control Picoh). Remember when we use the keyboard to control Picoh, Picoh’s head will only continue to move up and down as long as the N (for nod) 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.
What did we learn to do in the previous session? (Use the keyboard to control Picoh). Remember when we use the keyboard to control Picoh, Picoh’s head will only continue to move up and down as long as the N (for nod) 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 1
Ask the children to open the Picoh application on their computer 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 the number of 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).
Ask the children to open the Picoh application on their computer 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 the number of 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).
Activity
1. Write a program to make Picoh’s head move up and down 10 times.
File, Save As - headnodwithrepeat
1. Write a program to make Picoh’s head move up and down 10 times.
File, Save As - headnodwithrepeat
.2. Can you write a program that will make Picoh shake its head twice and then look straight ahead?
File, Save As – crossingtheroad
File, Save As – crossingtheroad
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
File, Save As – keepfit
Extension
Can you write your own keep fit sequence for Picoh with at least 3 moves and using repeat?
File, Save As – mykeepfit
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.
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.