1. Iteration Revisited

Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that computers do well and people do poorly.

Repeated execution of a sequence of statements is called iteration. Because iteration is such a common task, Python provides several language features to make it easier. We’ve already seen the for statement in a previous chapter. This is a very common form of iteration in Python. In this chapter we are going to review the for loop and then introduce the while loop — another way to have your program do iteration.