+ 1
Unreachable code
I want some unreachable codes for my project purpose I m Designing Dead code/ Unreachable code detection tool Code which will compile but never execute.. or does not impact on output
8 Respostas
+ 4
def f(x):
if x < 5:
return True
else:
return False
print('unreachable')
for i in range(85):
break
print('unreachable')
for i in range(10, 19):
if i:
continue
print('unreachable')
for i in range(16, 5):
print('unreachable')
if not 12:
print('unreachable')
+ 4
Loeschzwerg All of them are valid code. However range(16, 5) will be an empty range and the code in it will be unreachable
+ 3
I'd rather say write a function like this :
def my_function :
#your code
return something
#unreachable code (because of the return statement
+ 3
Ahh right.. Currently I work in a language where this would produce a reversed range (16,15,14,..,5) my mistake
+ 2
Thanks everyone giving your answers
+ 2
Anna
The secondlast is valid code, that will be executed, iirc
+ 1
Just write a function with no return and/or don't output anything to a file/stdout/stderr?
+ 1
So you design a linter for python?
Go with functions, that are never called in the code