Introduction¶
In programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached. Typically, a certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number.
Types of loops¶
There are two types of loops in Python.
- while
- for
Use a for
loop when you know how many times the loop should run. If you want the loop to break
based on a condition other than the number of times it runs, you should use a while
loop.