Unit 3: Loops and Repetition
Computers are brilliant at doing the same thing over and over — infinitely faster and more reliably than humans. This unit teaches you to harness that power with loops.
Lessons in This Unit
| Lesson | Title | Key Concepts |
|---|---|---|
| Lesson 8 | While Loops | while, counter variables, infinite loops, +=, break preview |
| Lesson 9 | For Loops and range() | for, range(start, stop, step), nested loops, enumerate() |
| Lesson 10 | IR Sensor, break, and continue | IR sensor wiring, break, continue, loop control |
New Hardware: IR Proximity Sensor
The IR sensor detects when an object is nearby by emitting infrared light and detecting reflections. Digital output — LOW when object detected.
What You’ll Be Able to Do by the End
- Use
whileloops for repeated actions and “wait until” patterns - Use
forloops to iterate a fixed number of times or through a list - Use
range()with start, stop, and step arguments - Use
breakto exit a loop early andcontinueto skip an iteration - Build LED animations and sensor-responsive programs
Loops are one of the most powerful tools in programming. After this unit, you can make your LED display complex animations and your programs respond continuously to sensors.