There are two types of loops, namely:
- Definite: In this case, the code of block runs for a defined number of times. This is useful when the programmer exactly knows in how many counts the task will be executed or let's assume that he knows the number of elements inside the data structure. For example, the strength of a classroom.
- Indefinite: In this case, the code of block runs until the condition is true. This is useful where the count is unknown. For example, trying to figure out the number of times London appears in a literary article.
Before further delving into loops, let's try to understand the range() and xrange() functions in Python.
The range() function comes handy when you want to generate a list on-the-fly. Its ...