Skip to content

Remove Redundant Continue

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 refactoring id: remove-redundant-continue

Section titled “Sourcery refactoring id: remove-redundant-continue”

Remove redundant continue statement

mylist2 = []
for i in mylist:
if i != 2:
mylist2.append(i)
else:
continue
mylist2 = []
for i in mylist:
if i != 2:
mylist2.append(i)

If a continue is not followed by any other statements in a for or while loop then it is not necessary, so can be removed. Removing unnecessary lines declutters the code and makes it easier to understand. This refactoring will only be triggered if it unlocks further improvements.