Affiliate disclosure
Book titles on this page link to Amazon. As an Amazon Associate, DataField.Dev earns from qualifying purchases — at no additional cost to you.
Further Reading: Repetition: Loops and Iteration
Python Loop Mechanics
-
Python Documentation: "More Control Flow Tools" —
forStatements andrange()(Tier 1) The official Python tutorial section onforloops andrange(). Concise and authoritative. Start here for the canonical explanation of Python's loop semantics. https://docs.python.org/3/tutorial/controlflow.html#for-statements -
Python Documentation: "The
whilestatement" (Tier 1) The formal language reference forwhileloops, including theelseclause. More technical than the tutorial, but complete. https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
Iteration as a Concept
-
Downey, A. Think Python, 3rd Edition, Chapter 7: "Iteration and Search." (Tier 1) An alternative explanation of loops with different examples and emphasis. Good for hearing the same concepts explained a second way. Free online. https://allendowney.github.io/ThinkPython/
-
Sweigart, A. Automate the Boring Stuff with Python, 3rd Edition, Chapter 3: "Loops." (Tier 1) Covers
while,for,range(),break, andcontinuewith small, practical programs, including a guess-the-number game. The rest of the book shows loops automating real tasks (renaming files, processing spreadsheets). Free online. https://automatetheboringstuff.com/3e/chapter3.html
Deeper Dives
-
Lutz, M. Learning Python, 6th Edition (2025), Chapter 13 ("while and for Loops") and Chapter 14 ("Iterations and Comprehensions"). (Tier 1) The most comprehensive treatment of Python's iteration protocol, including how
forloops work under the hood with iterators and iterables. More detail than you need right now, but valuable when you're ready for it (around Chapters 14-16 of this book). -
Beazley, D. & Jones, B. K. Python Cookbook, 3rd Edition, Chapter 4: "Iterators and Generators." (Tier 1) Advanced iteration patterns used in production Python code. Bookmarking for when you've finished this book.
The Accumulator Pattern in Practice
- Runestone Academy, Foundations of Python Programming, Section 7.6: "The Accumulator Pattern." (Tier 1) A short interactive lesson on the initialize-iterate-update structure, with exercises you can run in the browser. Free online. https://runestone.academy/ns/books/published/fopp/Iteration/TheAccumulatorPattern.html
Loop Performance and Optimization
- "Loop Like a Native" — Ned Batchelder, PyCon 2013 talk. (Tier 2)
An excellent conference talk about writing Pythonic loops, from
whileloops through iterators and generators. Covers when to useenumerate(),zip(), and other tools you'll learn in later chapters. Slides, text, and video are on the author's site. https://nedbatchelder.com/text/iter.html
For the Curious
-
"Turing & The Halting Problem" — Computerphile (YouTube video, 2014) (Tier 2) A six-minute video, presented by Mark Jago of the University of Nottingham, explaining why it's mathematically impossible to write a program that can determine whether any program will eventually halt (stop running) or loop forever. This is a deep connection between loops and the fundamental limits of computation mentioned in Chapter 1's "Three Big Questions of CS." https://www.youtube.com/watch?v=macM_MtS_w4
-
Knuth, D. E. "Structured Programming with go to Statements." Computing Surveys, 6(4), 1974, pp. 261-301. (Tier 2) A famous paper by one of computer science's greatest thinkers, written at the height of the debate over whether the
gotostatement should be abolished. Knuth finds merit on both sides: he proposes better loop and early-exit syntax so most programs need nogoto, while defending a few careful uses of it. Historical context for why we write loops the way we do.