The "for loop" loops (iterates) through the items of a sequence (string, list, tuple, dictionary, set ...). The "while loop" loops until a condition is met. Though the two loops are different beasts, they can overlap in functionallity. You can break out of either loop on a conditional statement.
If you want to loop a fixed number of times, it is easier to use a "for loop" ...
for k in range(100):
print "I should not cuss!"
Yes, there are other loops in Python. For instance a recursive function (a function that calls itself) is a loop for special purposes ...
# a recursive function to print n newlines
def new_lines(n):
if n > 0:
print
new_lines(n-1)
print "-----"
new_lines(20)
print "-----"
This is of course a silly application for a recursive function, just a demo. Below is a more common application of a recursive function ...
def gcd2(x, y):
"""greatest common denominator, recursive"""
if x > y:
return gcd2(x-y, y)
if x < y:
return gcd2(x, y - x)
if x == y:
return x
x = 14
y = 63
print gcd2(x, y) # 7
Interestingly the above recursive function can be replaced with a function containing a while loop and is much faster ...
def gcd3(x, y):
"""greatest common denominator, non-recursive"""
while y:
x, y = y, x % y
return x
x = 14
y = 63
print gcd3(x, y) # 7
I am digressing as usual!