Python Glossary Русский

all Python 3astterm

ast.Continue

control flow

The node of a continue statement, with no fields: it jumps to the next iteration of the innermost loop.

Syntax

ast.Continue()

As with break, ast.parse('continue') succeeds and only compile() reports the error, with a different message: 'continue' not properly in loop. Inside finally, continue is allowed only since 3.8, and from 3.14 on continue, break and return there trigger a SyntaxWarning. There are no fields, only positions.

Examples

import ast
tree = ast.parse('continue')
print(type(tree.body[0]).__name__, ast.Continue._fields)  # → Continue ()
try:
    compile(tree, '<src>', 'exec')
except SyntaxError as e:
    print(e.msg)  # → 'continue' not properly in loop

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy