iterate through loop python code example
Example 1: python loop
# A loop is used to iterate over a sequence
# The format of a loop is
for variable in object:
pass
# A common use of a for loop is using the range() function
for num in range(1, 10):
print(num)
# It can also be used with a list
new_list = ["Number 1", "Number 2", "Number 3", "Number 4"]
for x in new_list:
print(x)
Example 2: how to use iteration in python
for i = 1 to 10
<loop body>
Example 3: how to use iteration in python
n = 5
while n > 0:
print n
n = n-1
print 'Blastoff!'