.. _useless-else-on-loop:

useless-else-on-loop / W0120
============================

**Message emitted:**

Else clause on loop without a break statement, remove the else and de-indent all the code inside it

**Description:**

*Loops should only have an else clause if they can exit early with a break statement, otherwise the statements under else should be on the same scope as the loop itself.*

**Problematic code:**

.. literalinclude:: /data/messages/u/useless-else-on-loop/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/u/useless-else-on-loop/good.py
   :language: python



Created by the `basic <https://github.com/PyCQA/pylint/blob/main/pylint/checkers/base/basic_error_checker.py>`__ checker.