for loop in pyhton code example
Example 1: python loops
#x starts at 1 and goes up to 80 @ intervals of 2
for x in range(1, 80, 2):
print(x)
Example 2: loop in python
# A Sample Python program to show loop (unlike many
# other languages, it doesn't use ++)
# this is for increment operator here start = 1,
# stop = 5 and step = 1(by default)
print("INCREMENTED FOR LOOP")
for i in range(0, 5):
print(i)
# this is for increment operator here start = 5,
# stop = -1 and step = -1
print("\n DECREMENTED FOR LOOP")
for i in range(4, -1, -1):
print(i)
Example 3: python for loop
for num in range(5): # range(5) generates numbers from 0 to 4(inclusive)
print(num) # for each iteration num has value assigned by range function
Example 4: python for loop
for item in ['mosh','john','sarah']:
print(item)
Example 5: python for loop
for x in range(10):
print(x)
for x in range(10, 20, 2):
print(x)
list = [2, 3, "el"]
for x in list:
print(x)
for _ in range(10):
print("a");
Example 6: python loop
for i in range(1, 10);
print(i)