continue Statement

Imagine you are checking a bag of apples. You find one with a bruise, so you skip it and move to the next one. You don't throw away the whole bag! In Python, we use the continue statement to do exactly that—skip one part and keep going.

What is the Continue Statement?

The continue keyword tells Python to skip the current step of a loop and jump straight to the next one. Unlike break, it does not stop the loop completely.

It is the perfect tool for filtering data or ignoring specific values that you don't want to process.
                                                       

Real-World "Continue" Scenarios

  • Attendance: Check a list of students, but skip those who are absent.

  • Math Filters: Print all numbers from 1 to 10 but skip the negative ones.

  • Scheduling: Create a work plan but skip Saturdays and Sundays.

  • Cleaning: If you are sorting toys, skip the broken ones and keep sorting the rest.

How it Looks (Syntax & Examples)

The Pattern:

for item in list:
    if condition:
        continue  # The "Skip" Button

Example 1: The Missing Number

If we tell a loop to count to 5 but put a continue at 3:

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


Output: 1, 2, 4, 5

Example 2: The While Loop Filter

i = 1
while i <= 5:
    i += 1
    if i == 3:
        continue
    print(i)


Output: 2, 4, 5, 6

Summary:

    • Partial Skip: It only skips one iteration, not the whole loop.

    • Filtering: It's the best way to ignore unwanted values like empty spaces or errors.

    • Stay Active: Use it when you want the loop to keep running until the very end.

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

What does the continue statement do in a loop?

The continue keyword is used to skip a single cycle while letting the loop keep running.

Question 2

Which loops can use the continue statement?

Just like break, continue is a loop control statement that works in both for and while loops.

Question 3

If you want to print a list of names but skip "Voldemort," which statement should you use?

Using continue allows the program to ignore "Voldemort" but still print all the other names in the list.

Question 4

What is the main difference between break and continue?

Break exits the loop entirely, while continue just skips to the next iteration.

Question 5

In a loop of 10 items, if the continue condition is met at item #5, how many items will be processed in total?

The loop still attempts all 10 cycles, but the code inside the loop is only fully executed for 9 items because one was skipped.

Congratulations!

You've successfully mastered the knowledge check for "continue Statement."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic break Statement Next Topic Lists