Python continue statement:

The continue statement in Python is a loop control statement that forces to execute the next iteration of the loop while skipping the rest of the code inside the loop for the current iteration.

In other words, when the continue statement is executed in the loop, the code inside the loop following the continue statement will be skipped for the current iteration and the next iteration of the loop will begin.

Syntax :

The signature for the continue statement is as shown below.

continue

Flow diagram – continue statement :

Python continue statement

Python continue statement Examples:

Example 1: In this example, we will extract all the vowels from a string and build a new string without any vowel.

s="python programming"
v=['a','e','i','o','u']
t=""
for i in s:
	if i in v:
		continue
	else:
	    t+=i
print(t)

Output

pythn prgrmmng

Example 2: In this case, we will use the continue statement with a list of items.

#Initializing 
l1=['Mumbai','Thane','Palghar','Ratnagiri']
for city in l1:
	if city == 'Thane':
		continue
	else:	
		print (city)
	

Output

Mumbai
Palghar
Ratnagiri

Example 3: In this example, We will print the odd numbers from the list while skipping the even numbers.

#Initializing 
l=[123,23,22,54,66,36,447]
#Using continue
for i in l:
	if i%2==0:
		continue
	else:
		print(i)

Output

123
23
447

References

Happy Learning 🙂

Leave A Comment