Menu Close

Python Continue Statement

Python Continue Statement

Python Continue Statement

In this tutorial, we are going to learn what is Python Continue statement 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 is continue which helps to do this.

OR

Python continue statement is used to stop the current iteration of the loop and continue with 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

continue

Example Python Continue Statement

Example 1:

var = 0 # Second Example
while var < 10:              
   var = var  + 1
   if var == 5:
      continue
   print('Current variable value :', var)
print("Good bye!")

Output

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!

Example 2:

for i in range(1,11):
    if i == 5:
        continue
    print(i)

Output

1
2
3
4
6
7
8
9
10

Conclusion:

In this tutorial, you have learned what is Python Continue statement 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 next iteration.
I hope this tutorial will help you. if you like this tutorial, please comment and share with your friends who want to learn Computer Programming.

Python Break Statement
Python Pass Statement Tutorial

Was this post helpful?

Related Posts

Leave a Reply

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