How to End Current Iteration, and Continues to Next in Python Loops?

In this tutorial, we will learn how to end current iteration, and continues to next in Python Loops? By Pankaj Singh Last updated : April 13, 2023

End Current Iteration, and Continues to Next Iteration

To end current iteration, and continues to next, use the continue keyword, it stops the current iteration of the Loop and transfers the program's control to the next one.

Examples on Continue Statement

Practice the following examples to learn the concept of ending the current iteration and continues to the next in Python.

Example 1

In the given example, loop is running from 1 to 10 and we are using the continue statement if value of ‘i’ is 6. This when the value of i will be 6, program’s execution will continue without prating the 6.

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

Output

1
2
3
4
5
7
8
9
10

Example 2

In this example, we are printing character by character of the value/string “Hello world” and continuing the loop execution, if the character is space.

for ch in "Hello world":
    if ch == " ":
        continue
    print(ch)

Output

H
e
l
l
o
w
o
r
l
d

To understand the above programs, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.