Python Continue Statement

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

Sample Output:

Python continue statement inside a while loop
Python continue statement inside a while loop

Consider another example of a nested loop. Here, the continue statement will stop that inner loop where character ‘b’ is encountered.

Sample Output:

Python continue statement inside a nested loop
Python continue statement inside a nested loop

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!

Leave a Reply!

Your email address will not be published. Required fields are marked *