Break-Or-Continue-Outside-Loop¶
Sourcery rule id: break-or-continue-outside-loop
¶
Description¶
Remove break or continue statement found outside for or while loop
Before¶
def handle_invalid_number(numbers):
for number in numbers:
if is_valid(number):
continue
break
handle(number)
After¶
def handle_invalid_number(numbers):
for number in numbers:
if is_valid(number):
continue
handle(number)
Explanation¶
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.