Unreachable code | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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

13th Jun 2019, 7:40 AM
कामेश
कामेश - avatar
8 Réponses
+ 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')
13th Jun 2019, 8:22 AM
Anna
Anna - avatar
+ 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
29th Jun 2019, 9:56 AM
Anna
Anna - avatar
+ 3
I'd rather say write a function like this : def my_function : #your code return something #unreachable code (because of the return statement
13th Jun 2019, 8:04 AM
ThewyShift
ThewyShift - avatar
+ 3
Ahh right.. Currently I work in a language where this would produce a reversed range (16,15,14,..,5) my mistake
29th Jun 2019, 10:00 AM
Loeschzwerg
+ 2
Thanks everyone giving your answers
14th Jun 2019, 7:49 AM
कामेश
कामेश - avatar
+ 2
Anna The secondlast is valid code, that will be executed, iirc
29th Jun 2019, 9:45 AM
Loeschzwerg
+ 1
Just write a function with no return and/or don't output anything to a file/stdout/stderr?
13th Jun 2019, 7:50 AM
Jackson O’Donnell
+ 1
So you design a linter for python? Go with functions, that are never called in the code
13th Jun 2019, 8:28 AM
Loeschzwerg