Python Continue Statement
In this tutorial, we are going to learn what is Python Continue statement is and how can we use the continue statement to stop the current execution of iteration and continue with the next iteration.
In the previous tutorial, we have seen Python break statements that are used to terminate the flow of control.
What is Python Continue Statement ?
In Python, When you are using a loop like for loop and while loop and you want to stop the current iteration on a specific condition and continue with the next iteration, Then you have the best keyword available that continues which helps to do this.
Python continue statement is used to stop the current iteration of the loop and continue with the next iteration of the loop.
Why the use of a Continue statement in Python?
In Python programming, When you are using any loop like for loop, while loop and we want to skip the rest of the code inside a loop for current iteration only, Then we can use the continue statement.
Syntax of Continue statement in Python
Example Python Continue Statement
var = 0 # Second Example while var < 10: var = var + 1 if var == 5: continue print('Current variable value :', var) print("Good bye!")
Current variable value : 1 Current variable value : 2 Current variable value : 3 Current variable value : 4 Current variable value : 6 Current variable value : 7 Current variable value : 8 Current variable value : 9 Current variable value : 10 Good bye!
for i in range(1,11): if i == 5: continue print(i)
1 2 3 4 6 7 8 9 10
In this tutorial, you have learned what is Python Continue statement is and how to use Python continue statement to terminate the current iteration of the loop and continue with the next iteration. In Python, the continued statement is very useful because sometimes we want to stop the iteration on specific conditions and continue with the next iteration.
I hope this tutorial will help you. if you like this tutorial, please comment and share it with your friends who want to learn Computer Programming.