Session 10
Breaking down the problem into chunks (understanding procedures)
Objectives
Decompose the programming task into smaller parts
Identify sections of code which can be used several times and write a procedure for that section
Use repeat loops within procedures
Resources | Vocabulary |
---|---|
• Interactive White Board (IWB) • Levels 61 to 67 in Rapid Router • Resource sheets 1 and 2 • IKS3 Levels Guide • Advanced assets part 2 - Blockly Cards • Video: 'Edd explains functions' | • Procedure • Decompose • Define a procedure • Call a procedure |
Let's get started
Explain to students/to the class that often in programming, we need to do the same task at different times in the program.
We can write the code for this task or procedure and give it a name.
Then we can call the procedure in the program just by using its name.
What is the difference between a loop and a procedure?
Students may be confused about how a procedure is different from a loop. Loops are used to repeat actions, e.g. move forwards ten times.
Procedures are used to group together multiple lines of code that can then be called on from any part of a program. Procedures might be called from within a loop.
Let’s think about familiar situations where we are actually using procedures.
When a teacher says “stop” in class, what they actually mean is “stop talking, pencil down and face the front”. This is a set of instructions contained in the command “stop”. So that command is like a mini–program which we call a procedure. A teacher might use it several times in a lesson.
Another way of thinking about procedures is to look at verses which are used several times in a song or poem. Talk about songs and stories where you need to use the same words or lyrics at different points.
Watch the video of Michael Rosen performing ‘We’re going on a Bear Hunt’. Most students will be very familiar with this, but you could use a similar story/poem with familiar verses used in different stages of the narrative.
Can you spot which sets of lines are used more than once in different parts of the story?
They should find two obvious chunks:
‘We’re going on a bear hunt
We’re going to catch a big one
What a beautiful day
We’re not scared
Uh–oh’
Then:
‘We can’t go over it
We can’t go under it
Oh no!
We’ve got to go through it!’
Resource Sheet 1 has each ‘chunk of lines’ marked procedure 1 — bear hunt and procedure 2 — over and under.
Give procedure 1 to one group of four students and procedure 2 to another group of four.
Show the rest of the class the story structure on the IWB, explaining that they will perform the parts not covered by the procedures.
Ask the class to perform the poem, calling each group to perform procedure 1 and procedure 2 as needed.
Recap on the concept of a procedure just being a set of instructions which you name, and can be ‘called’ in a program at any time. Some students may have spotted some repeat loops in the story e.g. Repeat 3 (swishy swashy)
Return to Rapid Router Level 61 on the IWB. [fig S10.1]
Explain that the block of code to create a procedure is Define followed by the name you are giving to your procedure:
In your program, when you want to use that procedure, the block of code is Call:
Give each group a copy of the level screen from the levels guide. Ask the students to come up with a solution with their talk partners to create a procedure for the wiggle in the road.
There are several variations in how they might solve this, and it is a good opportunity to praise all attempts, explaining that there is often more than one algorithm which completes the task.
Make a note of the different solutions on a flip chart. The following is the ‘model solution’, the most efficient. Show this on the IWB and ask the students to check that it works and to compare it with their own solutions.
Paired activity
Students can try Levels 61 to 67 at their own pace, if you select similar ability pairs.
Alternatively, you may wish to start the activity off in mixed groups, to support those who find the concept challenging.
Ask them to work in pairs and use Resource Sheet 2 to design their program before creating the code on screen. Copies of the levels screenshots from the Levels Guide will be useful for some students. If you wish, you could do this as an unplugged activity before using the computers. [fig S10.2]
This will help the students discuss their thought processes and support the debugging if needed.
Share and review
Ask a few pairs of students to demonstrate and explain their program for a particular level.
Can you describe how you debugged your program?
Can you explain how your procedure works?
Follow-up unplugged activity
In a dance or PE session, put the students into small groups and ask them to write a procedure for a short dance move.
e.g.
Sidestep right
Sidestep left
Spin around
Clap
Name these procedures and teach them to the class.
Combine these procedures in a longer dance ’program’.
Extension activity or homework
In the Rapid Router Create mode, students could create their own pattern with a procedure used in several places and demonstrate it to the class.
Note: The next levels in the app are Blockly Brain teasers. These are intended as an additional challenge for students who are quick to learn, and can be used either in the classroom or at home.
Last updated