Section outline

    • 🌀 What is a Loop?

      A loop is a way to tell a robot (or a computer):

      “Keep doing this task again and again.”

       

      Instead of writing the same command 10 times, you use a loop to repeat it automatically.

    • 🧽 Real-Life Example

      Imagine you're asked to:

      • Sweep the floor

      • Sweep the floor

      • Sweep the floor

      • Sweep the floor...

      Instead of writing "sweep the floor" four times, you can say:

      “Repeat ‘sweep the floor’ 4 times.”

      That’s exactly what a loop does.


      🤖 Robot Example: Blinking Lights

      Let’s say your robot has an LED light.

      To blink it 5 times, you could use a loop like:

       

      Repeat 5 times: Turn light ON Wait 1 second Turn light OFF Wait 1 second 

      Without loops, this would need 10+ lines of code! Loops make it simple.

    • 🔂 Types of Loops (Made Easy)

      There are different types of loops, but for now, just understand two:

      1. Repeat X Times Loop

      – Used when you know how many times to repeat
      – Example: Blink 10 times

      Repeat Until Loop

      – Used when you don’t know how long it will run
      – Example: Repeat until robot reaches wall

      🛴 Real-Life Analogy

      Think of riding your bicycle 🚴:

      • You pedal again and again (loop)

      • Until you reach home (end condition)

      That’s a real-world loop with a stop condition!


      🛠️ Where Robots Use Loops

      • Line follower bots: Keep checking and adjusting direction

      • Cleaning robots: Keep cleaning until battery is low

      • Drones: Keep hovering until a command is given

    • 🎯 Activity: Spot the Loop

      Here's some robot code:

       

      Turn on motor Wait 1 sec Turn off motor Wait 1 sec Turn on motor Wait 1 sec Turn off motor Wait 1 sec Turn on motor Wait 1 sec Turn off motor Wait 1 sec 

      Can you rewrite this using a loop?


      🌟 Takeaway

      Loops are powerful tools.

      They make robots smarter, more efficient, and save you from writing the same thing again and again!