python for loop next iteration code example
Example 1: python continue
for i in range(10):
if i == 3:
continue
print(i)
Example 2: python return iteration number of for loop
for iteration, item in enumerate(iteratable_object):
print(iteration)
[iteration for iteration, item in enumerate(iteratable_object)]
your_list = ["a", "b", "c", "d"]
for iteration,item in enumerate(your_list):
(iteration, item)
--> (0, 'a')
(1, 'b')
(2, 'c')
(3, 'd')
[iteration for iteration, item in enumerate(your_list)]
--> [0, 1, 2, 3]
Example 3: python while continue
while True:
print('Who are you?')
name = input()
if name != 'Joe':
continue
print('Hello, Joe. What is the password? (It is a fish.)')
password = input()
if password == 'swordfish':
break
print('Access granted.')