Unnecessary "elif" after "break"
51 while True:
52 self.write("Do you want to download jadx? (Y/n) ", clr.OKBLUE)
53 choice = input().lower()
54 if choice == "": 55 choice = valid["y"]
56 break
57 elif choice in valid:
Description
The use of else
or elif
becomes redundant and can be dropped if the last statement under the leading if
/ elif
block is a break
statement.
In the case of an elif
after break
, it can be written as a separate if
block.
For else
blocks after break
, the statements can be shifted out of else
. Please refer to the examples below for reference.
Refactoring the code this way can improve code-readability and make it easier to maintain.
Bad practice
def changing_denominators(p, q):
while True:
if q == 0:
break
else:
print(p/q)
q = q - 1
Preferred:
def changing_denominators(p, q):
while True:
if q == 0:
break
print(p/q)
q = q - 1