انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

Repeat a number of times

Section 5: LoopsLesson 5.1 · ⏱ 7 min

Instead of writing the same blocks many times, put them once inside repeat and write how many times. This is called a loop.

Blocks: when 🚩 clicked, repeat (4)
🖥️ What happens on the stage?
Robo walks and turns 4 times, so he gets back to where he started after walking in a square.
📌 Note
Without repeat you would need 8 blocks. With the loop you need only 3, and the program is easier to read and change.

📌 Another example: the triangle

3 sides, and each time he turns 120 degrees (3 × 120 = 360), so Robo gets back to the start.

Blocks: when 🚩 clicked, go to x: (0) y: (0), point in direction (90), repeat (3)
The first side
The first side
Back at the start
Back at the start
✍️ Practise
Change the number to 8 and the angle to 45. What shape does Robo walk?
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Make Robo jump 3 times with repeat, then say “Done”.

👀 Show the solution
Blocks: when 🚩 clicked, go to x: (0) y: (0), repeat (3), say (Done) for (2) seconds
The result on the stage
The result on the stage
Medium

Make Robo switch his costume 5 times, waiting 0.3 seconds each time.

👀 Show the solution
Blocks: when 🚩 clicked, repeat (5)
After 5 costumes
After 5 costumes
Hard

Make Robo walk in a hexagon (6 sides). What is the angle? (360 ÷ 6)

👀 Show the solution
Blocks: when 🚩 clicked, go to x: (0) y: (0), point in direction (90), repeat (6), say (Hexagon ⬡) for (2) seconds
Hexagon: the angle is 60
Hexagon: the angle is 60
Finished the lesson? Mark it so your progress counts.