Use the continue statement inside the loop to skip to the next iteration in Python. However, you can say it will skip the current iteration, not the next one. But what we want to skip the code for this iteration in the loop.
So continue statement suits this situation.
Example skip to next iteration in Python
Simple example code.
Skip print() if number is 2.
for i in range(1, 5): if i == 2: continue print(i)
Python program to display only odd numbers.
for num in [1, 2, 3, 4, 5, 6]: # Skipping the iteration if number is even if num % 2 == 0: continue print(num)
Get the positive numbers list from the given list of numbers.
nums = [7, 3, -1, 8, -9] positive_nums =  for num in nums: if num < 0: # skips if negative num continue positive_nums.append(num) print(positive_nums)
Output: [7, 3, 8]
Do comment if you have any doubts or suggestions on this Python iteration tutorial.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.
it didnt work. My output is null.I dont know why.