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




