# KS1/FP: Finding out about procedures

In a computer program there are often sections of the program that we want to re-use or repeat. Chunks of instructions can be given a name – they are called functions and procedures. This lesson introduces procedures.

Aims

• Identify instructions that are repeated in a simple algorithm and set up a procedure
• Use the procedure in a new algorithm.

Background

Algorithms can be broken down into procedures or functions. This saves time by only having to execute (call) the function when it is required, instead of having to type out the whole instruction set again.

Programming languages have a set of pre-defined (also known as built-in) functions and procedures. If the programmer makes their own ones, they are custom-made or user-defined.

Procedures or functions?

Children do not need to know this at FP / KS1 but it might help you, as a teacher, to know that the simple difference is:

A procedure performs a task, whereas a function produces information.

Imagine you were programming a robot to move in a 1m square.  You could write a programme which told the robot to:

1. go forward 1m
2. turn 90.

This is a procedure. If you exercised that procedure 4 times, the robot would move in a square, ending up where it started.

A function, very simply, is a chunk of programme that takes an input expressed as a value(s), uses the value(s) to calculate something, then gives you a result.  For example, when you get a till receipt you might find there is a sum representing the cost of the goods, then underneath there is an extra line telling you what the VAT is before giving you a total.  There is a function in the till which takes the cost of the goods as the input, multiplies that by .2 (20%) and adds the resulting figure to the input.  Or you could have an input of 3 separate figures and a function which calculates the average.

If you have covered spreadsheets, then the instructions at the top of each column are ‘functions’.  If you are used to using robots, then the repeated concrete operations the robot performs are procedures

Activity

Take three or more routine ‘events’ where a substantial number of activities are repeated.

We used events in the school day that all the children were familiar with:

• Morning break time
• Lunch time
• Going home at the end of the afternoon.

We wrote down on cards what sequence of instructions or routine the children followed on each occasion. So for morning break it was:

• Go to the cloakroom
• Put your hat and coat on
• Walk out into the yard

At lunch time, it looked like this:

• Go to the dining hall
• Go to the cloakroom
• Put your hat and coat on
• Walk out into the yard

And at the end of the day it looked something like this:

• Tidy the classroom
• Say prayers
• Go to the cloakroom
• Put your hat and coat on
• Walk out into the yard
• Find the person who is picking you up
• Walk home

Clearly, you will need to adjust the instructions to correspond with your own circumstances.

First get the children to put the cards for each event in the order they would carry them out.  We stuck them with velcrodots on different coloured mounting card on the wall. Then ask them if they can see any cards that are the same and in the same order in each event.

When they have identified that (in our example) the cards

• Go to the cloakroom
• Put your hat and coat on
• Walk out into the yard

appear in that order somewhere in every event, then stick a set of these cards, in order, onto a piece of coloured card. We used velcro dots to do this as well.  This card is now a procedure.

If you then remove these common cards from each set on the wall, show that you can replace them with your ‘procedure’ card, which can be moved along into each event.

For reinforcement, take all the cards off the wall and ask the children to write the instructions for a new event e.g afternoon break or going for a class walk to the park on cards.  They can do this twice. Once writing out ALL the instructions and the second time using the procedure card.  Can they time themselves and see which is quicker?

Depending on how old the children are, you may want to introduce words such as ‘routine’ or ‘procedure’.

Talk about other occasions when they see an instruction that has to be repeated.  Examples might be a song book in which the chorus is written in full after the first verse but after all the other verses there is just the single word ‘Chorus’.   There are other examples where the ‘procedure’ is not written but represented by a picture or a sound.   Discuss what they have to do if they hear the fire alarm ring.  The sound of the alarm triggers a ‘procedure’ which they could write down.  Or they could use a picture of a bell as a ‘code’ for their procedure.

With older children, you could use a sport such as rugby or football.  What are the different ‘codes’ that the referee uses and what procedures are followed after he does?

We also asked the children to find a friend or relative that could knit or crochet and show them a knitting pattern which uses ‘repeat to end of row’.   Even better if they can see a garment with a repeated pattern. (This is actually a procedure repeated as a loop – but don’t worry about that just yet)

The software developers don’t have to write the code for these operations every time they build new programmes.  They will be able to call up a procedure for ‘log in or create account’ or for ‘choose a user name or password’ or for ‘your password must have 8 characters including one upper case character’ or whatever. And not every programmer will have to start from scratch and compile a long list of countries to click on.  All these are procedures, some of which they might have built themselves once upon a time or they may be built by other people who make them available to others.

Follow up can be writing down ‘procedures’ for the BeeBot. Or go to Nic Daniels lesson on using Lightbot.  He has just used the first few levels but if you get to level 4 it introduces procedures.

jen hughes

View my other posts