Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Const

continue

continue skips the rest of the current iteration and starts the next cycle of the nearest enclosing for or while loop. It has no arguments and is valid only in an appropriate loop context.

How it works

The continue statement skips the remaining body of the nearest enclosing for or while loop and starts its next cycle. It must be nested directly within such a loop, except that a function or class definition inside the loop does not make its own continue valid.

Syntax

continue

Key points

  • Its complete syntax is the single keyword continue.
  • Control resumes at the next cycle of the closest surrounding loop.
  • The statement is restricted to for and while loop bodies.
  • Definitions nested inside a loop do not extend the loop's valid continue scope.
  • A relevant finally clause runs before the loop advances.

Common mistakes

  • Using continue outside a for or while loop is invalid.
  • A continue inside a function or class body defined within a loop is not considered nested in that loop.
  • If continue leaves a try block with finally, the finally block runs before the next loop cycle.

Example: Skip selected loop iterations

for number in range(1, 6):
    if number % 2 == 0:
        continue
    print(number)

Prints only odd numbers by skipping the rest of each even-number iteration.

When to use it

Filter loop work

Ignore items that do not satisfy a condition while scanning a sequence.

Short-circuit an iteration

Skip optional processing while preserving the loop's remaining iterations.

Continue after guaranteed cleanup

Advance a loop after cleanup that must run in a finally block.

Interview questions

QWhat does continue do?

continue abandons the current iteration of the nearest enclosing loop and begins its next cycle. It does not terminate the loop itself.

Follow-up: How does it interact with finally? A finally clause executes before control starts the next loop cycle.

QWhere can continue appear?

The statement is syntactically permitted only inside a for or while loop. A function or class definition nested in that loop does not make continue valid inside its body.

Follow-up: Would a nested loop change the target? Yes; the nearest enclosing loop receives control.

QWhat is the syntax and control-flow target of continue?

The syntax is simply continue, with no expression or argument. It is a simple statement used to move directly to the next cycle of the nearest enclosing loop.

Follow-up: What happens to code after it in the current iteration? That code is skipped, while loop control proceeds to the next cycle.

  • break statement
  • for statement
  • while statement
  • try statement
  • finally clause

Source: 7. Simple statements — Python 3.15.0 documentation. Checked 2026-10-16.