Iteration

Repeated execution of a set of statements is called iteration. It can be used in many various situations.

The first script just counts the total number of steps to iterate through a range. These variables can be manipulated and a break statement could also be added if you wanted to stop the loop when the totalSteps was equal to a specific number.
ex:

if totalSteps == 5:  
    break
"""
Count the total number of steps to iterate through a range  
"""
#This variable is used to count the total number of steps taken
totalSteps = 0  
#Using a FOR loop we iterate through a range from
#0 to 20 with each step counting by 2
#20 is not included in the list.
for integer in range(0, 20, 2):  
    #Everytime the loop runs, we add 1 to the total
    totalSteps += 1

print('Total steps taken: ' + str(totalSteps))  
print('Final integer value: ' + str(integer))  

Result:

Total steps taken: 10  
Final integer value: 18  

You can also use iteration to count the total sum of numbers in a list. Thats great if you have a jumble of numbers and want to know what they add up to. It can also be used to count the number of words in a list.

""" 
Sum all the numbers in the list, and return the total.  
"""
#This variable is used to keep track of the current total
listTotal = 0  
#Using a FOR loop we iterate through a list and
#add the value of each integer to the listTotal
for x in [1, 2, 3, 4]:  
    #Keep track of the current list total and add
    #the next value of x in the list to it.
    listTotal = listTotal + x

print('The total of all numbers in the list: ' + str(listTotal))  

Result:

The total of all numbers in the list: 10  

This last example uses iteration to print an invitation to everyone in a list. You can manipulate variables such as date and byWhen and even convert them to take user input.
ex:

date = input('When is the event date? ')  
byWhen = input('By when should they RSVP? ')  
"""
Using iteration to print multiple RSVP invitations  
"""
#The date and byWhen varibles are set here but could also
#be placed within the statement,
#I set them as variables so that if later I want them to 
#take user input, it is a quick transition.
date = 'Dec 2'  
byWhen = 'Nov 1'  
#Iterate through the list, adding each name to the rsvp variable
for invite in ["Joe", "John", "Brandi", "Angelica", "Stacey", "Jennifer", "Thomas"]:  
    rsvp = "Hi " + str(invite) + ". Please RSVP for my event " + str(date) + ' by ' + str(byWhen)
    #Print the variable rsvp and then return back to the FOR loop for the next statement
    #until the entire list has been iterated.
    print(rsvp)

Result:

Hi Joe. Please RSVP for my event Dec 2 by Nov 1  
Hi John. Please RSVP for my event Dec 2 by Nov 1  
Hi Brandi. Please RSVP for my event Dec 2 by Nov 1  
Hi Angelica. Please RSVP for my event Dec 2 by Nov 1  
Hi Stacey. Please RSVP for my event Dec 2 by Nov 1  
Hi Jennifer. Please RSVP for my event Dec 2 by Nov 1  
Hi Thomas. Please RSVP for my event Dec 2 by Nov 1