---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:9:5
   |
 7 |         if i % 2:
 8 |             return i
 9 |     else:  # [useless-else-on-loop]
   |     ^^^^
10 |         print("math is broken")
11 |     return None
   |
help: Remove `else`
   |
8  |             return i
   -     else:  # [useless-else-on-loop]
   -         print("math is broken")
9  +     print("math is broken")
10 |     return None
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:18:5
   |
16 |     while True:
17 |         return 1
18 |     else:  # [useless-else-on-loop]
   |     ^^^^
19 |         print("math is broken")
20 |     return None
   |
help: Remove `else`
   |
17 |         return 1
   -     else:  # [useless-else-on-loop]
   -         print("math is broken")
18 +     print("math is broken")
19 |     return None
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:30:1
   |
28 |             break
29 |
30 | else:  # [useless-else-on-loop]
   | ^^^^
31 |     print("or else!")
   |
help: Remove `else`
   |
29 |
   - else:  # [useless-else-on-loop]
   -     print("or else!")
30 + print("or else!")
31 |
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:37:1
   |
35 |     while False:
36 |         break
37 | else:  # [useless-else-on-loop]
   | ^^^^
38 |     print("or else!")
   |
help: Remove `else`
   |
36 |         break
   - else:  # [useless-else-on-loop]
   -     print("or else!")
37 + print("or else!")
38 |
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:42:1
   |
40 | for j in range(10):
41 |     pass
42 | else:  # [useless-else-on-loop]
   | ^^^^
43 |     print("fat chance")
44 |     for j in range(10):
   |
help: Remove `else`
   |
41 |     pass
   - else:  # [useless-else-on-loop]
   -     print("fat chance")
   -     for j in range(10):
   -         break
42 + print("fat chance")
43 + for j in range(10):
44 +     break
45 |
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
  --> useless_else_on_loop.py:88:5
   |
86 |             else:
87 |                 print("all right")
88 |     else:  # [useless-else-on-loop]
   |     ^^^^
89 |         return True
90 |     return False
   |
help: Remove `else`
   |
87 |                 print("all right")
   -     else:  # [useless-else-on-loop]
   -         return True
88 +     return True
89 |     return False
   |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
   --> useless_else_on_loop.py:98:9
    |
 96 |         for _ in range(3):
 97 |             pass
 98 |         else:
    |         ^^^^
 99 |             if 1 < 2:  # pylint: disable=comparison-of-constants
100 |                 break
    |
help: Remove `else`
    |
97  |             pass
    -         else:
    -             if 1 < 2:  # pylint: disable=comparison-of-constants
    -                 break
98  +         if 1 < 2:  # pylint: disable=comparison-of-constants
99  +             break
100 |     else:
    |

PLW0120 [*] `else` clause on loop without a `break` statement; remove the `else` and dedent its contents
   --> useless_else_on_loop.py:144:5
    |
142 |     for j in range(10):
143 |         pass
144 |     else:
    |     ^^^^
145 |         # [useless-else-on-loop]
146 |         print("fat chance")
    |
help: Remove `else`
    |
143 |         pass
    -     else:
    -         # [useless-else-on-loop]
    -         print("fat chance")
    -         for j in range(10):
    -             break
144 +     # [useless-else-on-loop]
145 +     print("fat chance")
146 +     for j in range(10):
147 +         break
    |
