How Can We Help?
This tutorial will explain how to continue the loop in Python by giving practical examples for better understanding.
What is Continue Statement in Python?
The continue statement is a jump statement. When the program control reaches the continue statement, it skips the statements after “continue”. It then shifts to the next item in the sequence and executes its code block. We can use the continue statement in the while loop and for loop statements.
Python Continue Loop Syntax
loop_expression:
body of loop
continue
Python Continue Loop Example
i=0
while(i<3):
i=i+1
if(i==2):
continue
print(i)
Output:
1
3
Explanation:
- 1. for the first iteration, i=0, and after incrementing, it does not satisfy the if condition, so the output returns as ‘1’ against executing the “print(i)” statement of the loop.
- For the second iteration, “i=1”, and after increment, it becomes “i=2” which satisfies the if statement but the continue statement is given inside the if statement. It asks to skip the “print(i)” statement, so the output returns nothing.
- For the third iteration, “i=2”, and after incrementing, it does not satisfy the if condition, so the output returns as ‘3’ against executing the “print(i)” statement of the loop.
Conclusion
This tutorial taught us how to use loop continue statements in Python.
If you have an inquiry or doubt don’t hesitate to leave them in the comment section. we are waiting for your feedback.
But remember to understand the concept very well, you need to practice more.
Hopefully, it was clear and concise.
Python Tutorials List:
- Python tutorials list : access all python tutorials.