Python loops

Some time you may faced a situation where you need to execute a block of code several number of times. Programming languages provide control statements with repetition statements known as loops, which repeat an action.
Two types of loop
  1. Definite loop
  2. Indefinite loop
Definite loop : In this type, action is repeated predefined number of times.
Indefinite loop : In this type, action is repeated until the program determines that it need to stop In this page we will study about for and while loop. Before explaining the loop you should be acquainted with function range(). It generates lists containing arithmetic progressions.

range(start-value, end-value, difference between the values)

Example 1:

Description of image
So you have understood from example how function range() works Python has another range function called xrange().

xrange(start-value, end-value, difference between the values)
The xrange() allowing the memory to be freed, when the range list is not in use beacuse xrange() populates its range list whenever it is accessed by means of such as for loop. In next page you will see for loop.