3.6. Loops#
A fundamental component of computer programming is iteration. In other words - the ability to repeat tasks a number of times.
Often in programming you’ll find you need to repeat sections of code a number of times or you might need to perform the same calculation on a number of different variables.
In Python, we can repeat code using loops. There are two types of loops:
while
loopfor
loop
The type of loop you choose to use will often depend on the type of problem you want to solve, although you’ll see that some problems can be solved with either loop.