Filter loop work
Ignore items that do not satisfy a condition while scanning a sequence.
Python · Const
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.
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.
continuecontinue.for and while loop bodies.continue scope.finally clause runs before the loop advances.continue outside a for or while loop is invalid.continue inside a function or class body defined within a loop is not considered nested in that loop.continue leaves a try block with finally, the finally block runs before the next loop cycle.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.
Ignore items that do not satisfy a condition while scanning a sequence.
Skip optional processing while preserving the loop's remaining iterations.
Advance a loop after cleanup that must run in a finally block.
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.
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.
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 statementfor statementwhile statementtry statementfinally clause