Home » Python

continue statement in Python

Python continue statement: Here, we are going to learn about the continue statement in python with examples.
Submitted by IncludeHelp, on April 12, 2019

Python continue statement

Like other programming languages, in python, in python, continue statement is used to continue the loop executing by skipping rest of the statement written after the continue statement in a loop.

continue statement does not terminate the loop execution, it skips the current iteration of the loop and continues the loop execution.

Syntax of continue statement:

    continue

Python examples of continue statement

Example 1: Here, we are printing the serious of numbers from 1 to 10 and continuing the loop if counter’s value is equal to 7 (without printing it).

# python example of continue statement

counter = 1

# loop for 1 to 10
# terminate if counter == 7

while counter<=10:
	if counter == 7:
	    counter += 1 #increasing the counter
	    continue
	print(counter)
	counter += 1

print("outside of the loop")

Output

1 
2 
3 
4 
5 
6 
8 
9 
10
outside of the loop 

Example 2: Here, we are printing the characters of a string and continuing the loop to print of the characters if the character is not an alphabet.

# python example of continue statement

string = "IncludeHelp.Com"

# terminate the loop if 
# any character is not an alphabet 

for ch in string:
    if not((ch>='A' and ch<='Z') or (ch>='a' and ch<='z')):
        continue
    print(ch)

print("outside of the loop")

Output

I
n
c
l
u
d
e
H
e
l
p
C
o
m
outside of the loop





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.