Programming languages provide various control structures that allow for more complex execution paths. Loop statements allow us to execute a statement or group of statements multiple times
Python loop statement syntax
Python provides for loops and while loops (there is no do..while loop in Python)
Python loop statement example
while loop statement
#!/usr/bin/python count = 0while (count < 9): print 'The count is:', count count = count + 1 print "Good bye!"
for loop statement
#!/usr/ bin/python# -*- coding: UTF-8 -*- for letter in 'Python': # first instance print 'Current letter:', letter fruits = ['banana', 'apple', 'mango']for fruit in fruits: # The second example print 'Current fruit:', fruit print "Good bye!"