Continue

Python · Loops

Theory

continue skips the rest of the current pass of a loop and jumps straight to the next one. In a for loop that means taking the next item; in a while loop it means going back to check the condition. In the example, every even n makes n % 2 == 0 true, so continue skips the print for that n, and the output is just the odd numbers 1 and 3. Unlike break, the loop keeps running until it naturally finishes.

continue is often used as a guard clause: check for data you want to ignore at the top of the body (a blank line, a missing value, a cancelled order) and continue, so the main logic below stays unindented and easy to read. In a while loop, be careful that the variable update still happens: if count += 1 sits after the continue, skipping it can create an infinite loop. continue only affects the innermost loop.

Why we use it

Real data contains rows you want to skip: blanks, headers, invalid values. continue lets you drop those cases early in the loop body without wrapping all the remaining code in an extra if block.

When to use it

Use continue to skip unwanted items while still processing the rest. Use break when you want to stop the loop completely. If you are only filtering to build a new list, a comprehension with an if is usually cleaner.

How it works

  1. for n in range(5): takes the next n
  2. Is n % 2 == 0 (even)? Yes: continue: skip the rest of this pass. No: print(n).
  3. Go to the next item
  4. Any items left? Yes: Next pass. No: Loop ends normally.
  5. Output: 1 and 3

Syntax

for item in iterable:
    if condition:
        continue

Example

for n in range(5):
    if n % 2 == 0:
        continue
    print(n)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic