my_list = [10, 20, 30, 40, 50]
## Regular looping using range object
for i in range(len(my_list)):
print(my_list[i]) # [10,20,30,40,50]
## Pythonic loops
for v in my_list:
print(v) # [10,20,30,40,50]
# or
for a in [10, 20, 30, 40, 50]:
print(a) # [10,20,30,40,50]
## There's also a 'else' condition, when a 'for' loop is not executed
# if no statement has executed inside a 'for' loop,
# this 'else' condition will execute
for v in []:
print("List has no elements")
else:
print("So this will execute") # So this will execute