The for Loop & range()

Programming for ML with no experience — if you can type, you can begin

Some jobs repeat until something else decides to stop them. Keep asking a friend to guess your number until they get it right; keep stirring a sauce until it stops being lumpy. You cannot say in advance how many tries that will take, and the while loop lesson is built for exactly that kind of not-knowing. Other jobs repeat a fixed, known number of times, with nothing deciding to cut them short: water twelve plants, stamp fifty envelopes, visit every house on a route. Before you take a single step, you already know the count. This lesson is about the loop Python gives you for that second kind, the for loop.

🔒 This is a Pro lesson — the interactive figure, worked examples, quiz and practice open with Pro access.

▶ The for Loop & range()
← The while LoopA Loop Is a Σ →