Continue statement is helpful when you want to stop the current iteration in a loop based on a condition. i.e if a condition is true, then stop the current loop iteration and go to the next iteration.
Look at the code snippet below. If the value of the counter is equal to 2 then that iteration will not print the value of counter, and it will go on to the next iteration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# Creating a counter counter=1 # Run while condition is true while counter < 5: if(counter==2): counter += 1 # Exit the current iteration continue print(counter) else: print(counter) counter += 1 |
Sample Output:

Consider another example of a nested loop. Here, the continue statement will stop that inner loop where character ‘b’ is encountered.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Another example of continue statement # Creating sample objects sampleList=[10,20,30,40] sampleTuple=['a','b','c','d'] # Nested for loop for multiple iterators for numIterator in sampleList: for charIterator in sampleTuple: # Exit the current iteration if 'a' is encounterd if(charIterator=='b'): continue print(numIterator, '--', charIterator) |
Sample Output:

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!