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. True or false? The robot moves 1 squares.
Tunjuk jawapan
Jawapan: Salah. The loop repeats "move ←" 3 times, so the robot moves 3 squares.
2. Which loop makes the robot do exactly these moves?
- repeat 6 × →
- repeat 7 × →
- repeat 6 × ←
- repeat 5 × →
Tunjuk jawapan
Jawapan: repeat 6 × →. The moves → happen 6 times, so "repeat 6 × →" does the same job with less code.
3. Which loop makes the robot do exactly these moves?
- repeat 3 × ↓
- repeat 2 × ↑
- repeat 3 × ↑
- repeat 4 × ↑
Tunjuk jawapan
Jawapan: repeat 3 × ↑. The moves ↑ happen 3 times, so "repeat 3 × ↑" does the same job with less code.
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.