This notebook contains an excerpt from the Python Programming and Numerical Methods - A Guide for Engineers and Scientists, the content is also available at Berkeley Python Numerical Methods.
The copyright of the book belongs to Elsevier. We also have this interactive book online for a better learning experience. The code is released under the MIT license. If you find this content useful, please consider supporting the work on Elsevier or Amazon!
< Chapter 4 Summary and Problems | Contents | 5.1 For Loops >
Chapter 5. Iteration¶
Motivation¶
Many tasks in life are boring or tedious because they require doing the same basic actions over and over again—iterating—in slightly different contexts. For example, consider looking up the definition of 20 words in the dictionary, populating a large table of numbers with data, alphabetizing many stacks of paper, or dusting off every object and shelf in your room. Since repetitive tasks appear so frequently, it is only natural that programming languages like Python would have direct methods of performing iteration.
This chapter teaches you how to program iterative tasks. With branching and iteration, it is possible to program just about any task that you can imagine.