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 while loops for repeated actions and “wait until” patterns
  • Use for loops to iterate a fixed number of times or through a list
  • Use range() with start, stop, and step arguments
  • Use break to exit a loop early and continue to 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.


Copyright © Paul Baumgarten.