A loop repeats instructions. Instead of writing “move right” five times, a programmer writes “repeat 5 × move right”. Loops make programs shorter, clearer and easier to change.
Apa yang akan dipelajari anak anda
- Work out what a repeat loop does
- Count the total moves made by a loop
- Replace a long list of repeated steps with a loop
- Combine a loop with other instructions
Why loops matter
Loops are one of the most powerful ideas in coding. Loop Lagoon uses colourful code blocks, like the ones in Scratch and ScratchJr, so children learn to read the kind of code they will meet in real coding apps.
A great way to understand a loop is to “unroll” it: “repeat 3 × (→ ↑)” means → ↑ → ↑ → ↑.
Contoh soalan
Berikut ialah beberapa soalan seperti dalam misi pertama. Bolehkah anda menjawabnya?
1. True or false? The robot moves 3 squares.
Tunjuk jawapan
Jawapan: Betul. The loop repeats "move ↑" 3 times, so the robot moves 3 squares.
2. How many squares does the robot move?
- 2
- 4
- 6
- 7
Tunjuk jawapan
Jawapan: 4. The loop repeats "move ↑" 4 times, so the robot moves 4 squares.
3. How many squares does the robot move?
- 1
- 3
- 6
- 4
Tunjuk jawapan
Jawapan: 3. The loop repeats "move ←" 3 times, so the robot moves 3 squares.
Tip untuk orang dewasa
- Make up a dance with a loop: “repeat 4 times: clap, stamp”.
- Spot loops in songs and stories with repeating lines.