Divide the class into two teams. Invite students to play a simple game involving repeated actions; for example:
The winner is the team that has thrown the most goals after each player has had five attempts.
After playing the game, ask the students to write and/or draw their own version of the instructions (algorithm) to show others how to play. Invite students to share their algorithms and, through discussion, introduce the ‘repeat’ command. Demonstrate how the number of steps can be reduced by including ‘repeat’ in the algorithm. Ask students to consider how the score is counted and the game ends. They may include a command such as ‘repeat until each player has had a turn’; so their algorithm might include two loops; one nested inside the other.
Create an algorithm for different game play; for example:
Ask students to share examples of how repetition is used in familiar games or quizzes; for example, what actions are repeated and how do players know when a game has come to an end? How do we replicate this when coding a game or quiz? Explain that a common aspect of repetition is the inclusion of a condition that lets the computer know how many times to repeat a sequence of instructions.
Explain that repetition (iteration) is used to make programs more efficient.
Show students examples of blocks of code in visual programming environments where the repeat loop is used to repeat a single instruction multiple times; for example, environments such as Blockly, Snap or Scratch.
Ask students to work in small groups, and use a visual programming language to create their own simple maze, quiz or game within the context of a learning area. Algorithms must include repeat instructions and structures such as reading user input until a correct answer/successful outcome is given. Students need to consider the sequence of the blocks of code and functional requirements such as navigation buttons.
Encourage students to interact with each other’s games, and to consider the following:
Reinforce the students’ understanding of the concept of repetition (iteration). Repetition allows us to complete an action multiple times. Explain that when programming we use repetition to solve problems more efficiently.
In the Digital Technologies curriculum, students in years 5 and 6 are expected to include repetition (iteration) in their programming solutions, as well as decision-making and user-interface design. When creating their solutions students increase the sophistication of their algorithms by identifying repetition and incorporating repeat instructions.
Repetition is commonly used when creating algorithms and is an important concept of computational thinking. Repetition allows us to complete a common task multiple times, even when the information or context changes. A common component of repetition is a condition that tells the computer how many times to repeat a sequence of instructions.
Examples of repetition in the behaviour of software systems include the algorithm that controls the behaviour of the scanner at the supermarket; and the algorithm that controls the behaviour of robotic devices.