Iteration: repeating steps

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Iteration: repeating steps

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which one is an example of iteration?
A Doing each step once and then stopping
B Repeating the same steps instead of writing them out again
2. You write: clap, clap, clap, clap, clap. How could you write this with iteration?
A REPEAT 5 TIMES: clap
B clap 5 TIMES REPEAT
3. Why do programmers use loops?
A Loops save effort because we don't write the same steps again and again
B Loops make a computer forget the steps it already did
4. The steps that get repeated inside a loop are called the...
A loop ending
B loop body
5. Which list of steps has a repeated pattern you could turn into a loop?
A step forward, turn, step forward, turn, step forward, turn
B wake up, eat breakfast, brush teeth, catch the bus

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1REPEAT 4 TIMES AThe loop body is not clearly shown. The steps to repeat should be indented under REPEAT so we know which steps are in the loop.
2REPEAT 3 TIMES clap BThe loop body is the clap step, because it is the part that gets repeated
3Loops save effort: one loop does the work of writing the same steps many times CIteration: the steps inside are repeated 4 times, so you don't write them out four times
4Spotting repeated steps: the same steps appear over and over, so they can go in a loop DThe same step is written out again and again. A loop like REPEAT 5 TIMES with wave inside would save effort.
5REPEAT 3 TIMES clap stomp Estep forward step forward step forward
6wave wave wave wave wave FREPEAT 5 TIMES jump

Definitions

iteration

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ 4 TIMES clap END REPEAT
2.
// Stomp 5 times REPEAT _ TIMES stomp
3.
// Clap 3 times REPEAT 3 TIMES ____
4.
REPEAT 6 _____ jump END REPEAT
5.
REPEAT 3 TIMES spin END ______

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A REPEAT TIMES
B Move forward 10
C Turn right 90
D END REPEAT
Question 2
A Pick up the toothbrush
B REPLAY 10 TIMES
C Brush one tooth
D END REPEAT
E Rinse your mouth
Question 3
A Get a skipping rope
B REPEAT 20 TIMES
C Jump over the rope
D STOP REPEAT
E Put the rope away
Question 4
A Collect the blocks
B REPEAT 8 TIMES
C Knock the tower down
D END REPEAT
Question 5
A # Draw a triangle
B REPEAT 4 TIMES
C Move forward 50
D Turn right 120
E END REPEAT

Answer Key

Iteration: repeating steps
Section A: Quick Questions
Q1
B — Repeating the same steps instead of writing them out again
Q2
A — REPEAT 5 TIMES: clap
Q3
A — Loops save effort because we don't write the same steps again and again
Q4
B — loop body
Q5
A — step forward, turn, step forward, turn, step forward, turn
Section B: Match the Pairs
Q1
REPEAT 4 TIMES → Iteration: the steps inside are repeated 4 times, so you don't write them out four times
Q2
REPEAT 3 TIMES clap → The loop body is the clap step, because it is the part that gets repeated
Q3
Loops save effort: one loop does the work of writing the same steps many times → REPEAT 5 TIMES jump
Q4
Spotting repeated steps: the same steps appear over and over, so they can go in a loop → step forward step forward step forward
Q5
REPEAT 3 TIMES clap stomp → The loop body is not clearly shown. The steps to repeat should be indented under REPEAT so we know which steps are in the loop.
Q6
wave wave wave wave wave → The same step is written out again and again. A loop like REPEAT 5 TIMES with wave inside would save effort.
Section C: Definitions
Q1
iteration — Repeating a set of steps instead of writing them out again and again. The repeated steps are called the loop body. Loops save effort.
Section D: Fill in the Blanks
Q1
REPEAT 4 TIMES clap END REPEAT
Q2
// Stomp 5 times REPEAT 5 TIMES stomp
Q3
// Clap 3 times REPEAT 3 TIMES clap
Q4
REPEAT 6 TIMES jump END REPEAT
Q5
REPEAT 3 TIMES spin END REPEAT
Section E: Spot the Error
Q1
A — A loop must say how many times to repeat. The first line should be REPEAT 4 TIMES so the loop body runs 4 times.
Q2
B — The keyword that starts a loop is REPEAT, not REPLAY. It should be REPEAT 10 TIMES.
Q3
D — The loop body must be closed with END REPEAT. STOP REPEAT is not the right ending, so line 4 should be END REPEAT.
Q4
C — The loop body is the step that gets repeated, and it should help build the tower. Line 3 should be Stack one block, not knocking the tower down.
Q5
B — A triangle has 3 sides, so the loop body must repeat 3 times. Repeating 4 times would draw too much. It should be REPEAT 3 TIMES.