Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
This chapter concludes our tour of Python procedural statements by
presenting the language’s two main looping constructs—statements that repeat an
action over and over. The first of these, the while statement, provides a way to code general
loops. The second, the for statement, is designed for stepping through
the items in a sequence object and running a block of code for
each.
We’ve seen both of these informally already, but we’ll fill in
additional usage details here. While we’re at it, we’ll also study a few
less prominent statements used within loops, such as break and continue, and cover some built-ins commonly
used with loops, such as range,
zip, and map.