Recognizing and Avoiding Dead Code
In this lesson, you’ll learn how to identify dead code in your functions. When a function reaches a
return statement, it immediately ends execution of that function and returns a value to the calling environment.
Recall our version of the absolute value function. Even though there was a second
return statement after a first one, the second one isn’t considered dead code because there is a path of execution which can arrive there.
The first one is inside this
if statement, so it won’t be executed if the condition is
False. So be careful to watch for what is and what isn’t dead code in your functions, and then always correct your functions so that they don’t have any dead code.
Become a Member to join the conversation.