Skip to content

Break-Or-Continue-Outside-Loop

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Sourcery rule id: break-or-continue-outside-loop

Section titled “Sourcery rule id: break-or-continue-outside-loop”

Remove break or continue statement found outside for or while loop

def handle_invalid_number(numbers):
for number in numbers:
if is_valid(number):
continue
break
handle(number)
def handle_invalid_number(numbers):
for number in numbers:
if is_valid(number):
continue
handle(number)

The break and continue are used to control the behaviour of for and while loops. Using them outside those loops is a SyntaxError.

This error may be very easy to pass through since sometimes it is caused by a wrong indentation.