Lesson 24 of 70 – Python Continue Statement
34%

Python Continue Statement

The continue statement is used to skip the remaining code of the current iteration of a loop and move directly to the next iteration.

Note: Unlike break, the continue statement does not stop the loop. It only skips the current iteration.
What is the Continue Statement?

The continue statement tells Python to skip the remaining statements in the current loop iteration.

for variable in sequence:

    if condition:
        continue

    statement

After continue executes, Python moves to the next iteration.

Simple Continue Example
for i in range(1, 6):

    if i == 3:
        continue

    print(i)
Output:
1
2
4
5

When i is 3, continue skips the print statement for that iteration.

How Continue Works
  1. The loop starts normally.
  2. Python checks the condition.
  3. If the continue condition is True, continue executes.
  4. The remaining statements in that iteration are skipped.
  5. The loop moves to the next iteration.
Continue with While Loop
i = 0

while i < 5:

    i += 1

    if i == 3:
        continue

    print(i)
Output:
1
2
4
5
Skip Even Numbers
for i in range(1, 11):

    if i % 2 == 0:
        continue

    print(i)
Output:
1
3
5
7
9

The continue statement skips all even numbers.

Skip Odd Numbers
for i in range(1, 11):

    if i % 2 != 0:
        continue

    print(i)
Output:
2
4
6
8
10
Continue with List
numbers = [10, 20, 30, 40, 50]

for number in numbers:

    if number == 30:
        continue

    print(number)
Output:
10
20
40
50
Continue with String
text = "Python"

for letter in text:

    if letter == "h":
        continue

    print(letter)
Output:
P
y
t
o
n
Continue with Condition
for i in range(1, 11):

    if i < 5:
        continue

    print(i)
Output:
5
6
7
8
9
10
Continue with While Loop and Condition
i = 0

while i < 10:

    i += 1

    if i <= 5:
        continue

    print(i)
Output:
6
7
8
9
10
Continue with User Input
for i in range(5):

    number = int(input("Enter a number: "))

    if number < 0:
        continue

    print("Positive number:", number)

If the user enters a negative number, the print statement is skipped for that iteration.

Skip a Particular Value
for i in range(1, 11):

    if i == 7:
        continue

    print("Number:", i)
Output:
Number: 1
Number: 2
Number: 3
Number: 4
Number: 5
Number: 6
Number: 8
Number: 9
Number: 10
Continue in Nested Loop

When continue is used inside a nested loop, it affects the nearest loop containing it.

for i in range(1, 4):

    for j in range(1, 4):

        if j == 2:
            continue

        print(i, j)
Output:
1 1
1 3
2 1
2 3
3 1
3 3
Continue with Multiplication Table
number = 5

for i in range(1, 11):

    if i == 5:
        continue

    print(number * i)
Output:
5
10
15
20
30
35
40
45
50

The fifth multiplication result, 25, is skipped.

Continue with List of Names
names = ["Amit", "Rahul", "Ravi", "Priya"]

for name in names:

    if name == "Ravi":
        continue

    print("Hello", name)
Output:
Hello Amit
Hello Rahul
Hello Priya
Continue vs Break
Continue Break
Skips the current iteration. Stops the entire loop.
The loop continues. The loop terminates.
Used when a particular value should be skipped. Used when the loop should stop completely.
Continue vs Pass

Continue:

for i in range(5):

    if i == 2:
        continue

    print(i)
Output: 0, 1, 3, 4

Pass:

for i in range(5):

    if i == 2:
        pass

    print(i)
Output: 0, 1, 2, 3, 4

The pass statement does nothing, while continue skips the remaining code of the current iteration.

Continue with Dictionary
students = {
    "Amit": 80,
    "Rahul": 45,
    "Priya": 90
}

for name, marks in students.items():

    if marks < 50:
        continue

    print(name, marks)
Output:
Amit 80
Priya 90
Continue with Marks
marks = [35, 65, 40, 80, 25, 90]

for mark in marks:

    if mark < 40:
        continue

    print("Pass:", mark)
Output:
Pass: 65
Pass: 40
Pass: 80
Pass: 90
Continue with Positive Numbers
numbers = [10, -5, 20, -3, 30]

for number in numbers:

    if number < 0:
        continue

    print(number)
Output:
10
20
30
Important: Continue in While Loop

When using continue in a while loop, make sure the loop variable is updated before continue. Otherwise, the loop may become infinite.

i = 0

while i < 5:

    i += 1

    if i == 3:
        continue

    print(i)
Output:
1
2
4
5
Continue with Else

Unlike break, continue does not terminate the loop. Therefore, the loop can still finish normally and its else block can execute.

for i in range(1, 5):

    if i == 2:
        continue

    print(i)

else:
    print("Loop completed")
Output:
1
3
4
Loop completed
Real-Life Example

Suppose we have a list of student marks and want to display only passing marks.

marks = [25, 45, 30, 70, 85]

for mark in marks:

    if mark < 40:
        continue

    print("Passed:", mark)
Output:
Passed: 45
Passed: 70
Passed: 85
Important Rules
  • continue skips the current iteration.
  • It does not stop the complete loop.
  • It can be used with for and while loops.
  • It is useful for ignoring unwanted values.
  • In nested loops, it affects the nearest loop.
  • In a while loop, update the loop variable carefully before continue.
  • continue is different from break and pass.
Key Points
  • The continue statement skips the current iteration.
  • The loop continues with the next iteration.
  • It does not terminate the loop.
  • It can be used with both for and while loops.
  • It is useful for skipping unwanted values.
  • In a nested loop, continue affects the nearest loop.
  • Continue and break have different purposes.
  • Continue and pass also behave differently.

🧠 Quick Quiz

Question: What does the continue statement do in Python?