Year 3 loops go further: loops that repeat several instructions, loops mixed with other code, and nested loops — a loop inside another loop.
Apa yang akan dipelajari anak anda
- Work out what loops with several instructions do
- Count the actions in a nested loop
- Combine loops with other instructions
- Rewrite repeated code as a loop
Loops inside loops
A nested loop repeats a loop. “Repeat 3 × (repeat 4 × clap)” gives 3 × 4 = 12 claps. Nested loops connect coding with multiplication, which children are learning at the same age.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. Which loop makes the robot do exactly these moves?
- repeat 4 × ←
- repeat 3 × ←
- repeat 2 × ←
Tunjuk jawapan
Jawapan: repeat 3 × ←. The moves ← happen 3 times, so "repeat 3 × ←" does the same job with less code.
2. How many squares does the robot move?
- 7
- 8
- 5
- 6
Tunjuk jawapan
Jawapan: 5. The loop repeats "move ↑" 5 times, so the robot moves 5 squares.
3. How many squares does the robot move?
Tunjuk jawapan
Jawapan: 12. Each time round the loop the robot moves 2 squares. 6 × 2 = 12.
4. How many claps?
- repeat 2: (repeat 3: clap)
- repeat 3: (repeat 3: clap)
- repeat 4: clap
- 9 claps
- 4 claps
- 6 claps
Tunjuk jawapan
Jawapan: repeat 2: (repeat 3: clap) → 6 claps · repeat 3: (repeat 3: clap) → 9 claps · repeat 4: clap → 4 claps. In a nested loop, multiply: 2 × 3 = 6.
Tip untuk orang dewasa
- Act out nested loops: “3 times: do 4 jumps”.
- Ask your child to write a loop for a dance or exercise routine.