Skip to content

break-outside-loop

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports a break that no loop of its function or class contains.

Python rejects the file with SyntaxError: 'break' outside loop, so no code in it runs.

To fix, remove the break, or put the statement in the loop it is meant for. In a function, return leaves it.

Reported
...
x = 1
...
break
...
python:
lint:
rules:
break-outside-loop: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line break-outside-loop in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff F701 full