Using simple selection and repetition: repeat until at destination and if… do...
Understand selection using the if… do... statement
Understand that you can use an if statement inside a repeat loop
Use this knowledge to create short efficient programs to complete simple single routes
Explain that in all programming languages, there is a way of asking a question and telling the computer what to do, depending on the answer. This is the if… do... statement: if it is raining do put your coat on. If it is sunny do put on sun cream. Ask the students to come up with their examples.
Watch video: ‘Chris and Matt introduce if statements’ to help the students understand how important the little statement if is in programming.
So for our van, if the road ahead goes straight forwards do move forwards. Model this as a van driver — or ask a student to do so, going along a masking tape path.
The blocks of code have to be more precise than our spoken language, so we will need to use: if road exists forwards... do [move forwards]
Draw three routes on the IWB:
Road going forward
Road turning right
Road turning left
Ask the students what the computer will do with the van in each case, if it follows the if statement: if road exists forwards... do [move forwards]
Do the same for the following if statements:
if road exists right... do [turn right]
if road exists left... do [turn left]
Demonstrate how this can work at level 33 [fig S3.1], inside the repeat loop. Drag the repeat block and the if... do... block into the workspace.
Why do we need to put the if statement inside the repeat until at destination loop? (Otherwise the computer will only ask the question once and after one move forward, the van would stop).
What happens if there is a turn in the road? Look at level 34 [fig S3.2].
What instruction would we need to add?
Give the students time to test this out, using levels 33 to 35.
Arrange the students into groups of four to discuss what they have found. Tell them that you will choose a spokesperson from two groups at random to explain the group’s method to the class.
Can you explain your algorithm using correct programming language?
Unplugged activity to consolidate understanding — choose one child to be the van driver, lay out a ‘road’ for the driver to follow with some right and left turns (you can do this with masking tape, construction blocks or even by creating a route with the classroom tables).
Give one student the resource sheet [fig S3.3] to hold up at the end of the route.
Put the code on the IWB and enlarge:
Ask another student to read out the blocks of code [fig S3.4]. The driver only moves when the if statement that is being read out is satisfied. Help by pointing to each block of code on screen in turn and cycle round and round the repeat loop until the destination is reached.
Can you explain how this algorithm works?
Can you describe which questions the computer asks and what it does depending on the answer?
Add the if… do... statement to your code wall display with students’s written explanation of how it works.
Resources | Vocabulary |
---|---|
• Levels 33 to 35 in Rapid Router
• Resource sheet
• Video 'Chris and Matt introduce if statements'
• Interactive Whiteboard (IWB)
• If ... do
• Selection
• Debug