liveBook · Manning

Continue statement

As explained in Python How-To

A continue statement skips the remaining body of the current loop iteration and proceeds to the next iteration when one exists.

A continue statement skips the remaining body of the current loop iteration and moves to the next iteration when one exists. Use it when only items meeting a criterion should receive the remaining operations. section 5.4.2

Use continue to keep loop logic readable:

  • Place it inside a conditional that identifies items to skip. section 5.4.2
  • Put the operations for qualifying items after the continue guard, reducing indentation. section 5.4.2
  • Treat it as a readability choice rather than a performance improvement when equivalent conditions process the same items. section 5.4.2

Skip numbers below three

for number in range(5): if number < 3: continue print(f"Number: {number}") # Output: Number: 3 Number: 4 section 5.4.2

for number in range(5):
    if number < 3:
        continue
    print(f"Number: {number}")
 
# output the following lines:
Number: 3
Number: 4

Follow the loop trace to see how continue suppresses output for the first three iterations and resumes normal processing afterward. section 5.4.2

How Python How-To covers it

How deep it goes
Explains control flow, filtering alternatives, and indentation trade-offs, but does not descend into interpreter internals.
Examples
Demonstrates numeric iteration and urgent-task processing with multiple operations guarded by complementary conditions.
What it assumes
Assumes basic conditional statements and loop iteration while developing the role of continue within iterable processing.
What you can do after
Apply it via Python for and while loops to bypass unnecessary operations for selected iterations.
How it connects
Connects continue with for loops, while loops, break statements, filtering, and iterables.

Also explained in

Compare how 5 books explain continue statement →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python How-To. The section links point to the parts of the book it draws on.