Python Loop Visualizer

A tool for understanding for loops and range().

Created by Sam Li

Learning Objectives

By the end of this module, you will be able to visualize how the range() function generates sequences of numbers, and understand how for loops use these sequences to execute repetitive tasks.

for i in range (
Start
,
Stop
,
Step
) :
print(i)

Console Output

Common Misconceptions

  • "Stop is included." False! The range() function uses an exclusive upper bound. range(0, 5) stops at 4.
  • "Step can be 0." False! If you don't step forward or backward, the loop would run forever. Python prevents this with an error.

Key Takeaways

  • range() generates numbers sequentially.
  • Syntax: range(start, stop, step)
  • start is inclusive (starts exactly here).
  • stop is exclusive (stops before this).

Think & Link

How would you code a countdown for a rocket launch from 10 down to 1?

Try it above: Set Start to 10, Stop to 0, and Step to -1!