Running code many times with loops

Loops are compound statements that repeat the code within them many times, a specific number of times, until a certain test is met, or even indefinitely. By doing so, loops enable us to incrementally update the values or traverse over a collection of values, computing something for each of them. For example, the factorization function we wrote at the end of the last chapter to illustrate recursing can be written with loops, multiplying the value by the next value in the row each time. 

Python loops have two main forms—for and while. Let's now look at them in detail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset