Python Continue Statement | How works For, while Loop Example

Python Continue Statement is a loop control statement and mainly used to skip an iteration or ignore that condition. It works opposite to that of a break statement.

Where break statement is instead of terminating the loop and Continue Statement forces to execute the next iteration of the loop.

Python Continue Statement example

There are more loop control statements.

Syntax

Examples:

The continue statement can be used in both while loop and for loop.

1. Python continue statement using in for loop

Below is the implementation of the above idea:

If condition statement with for-loop to check and skip if “a” word found.

Output:

D
t
The end

How continue statement works in Loop

Python continue statement in for loop

2. Python continue statement using in While loop

Using a while loop and if condition to skip a “2” number.

Output:

Current variable value : 4
Current variable value : 3
Current variable value : 1
Current variable value : 0
Good bye!

Do comment if you have any doubts and suggestions on this tutorial.

Note: This example (Project) is developed in PyCharm 2020.1 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.4
Python 3.7
All Python Programs are in Python 3, so it may change its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.