A good tip to keep in mind when programming is minimizing your use of else
statements. When possible, exit the function context earlier given a value that establishes the given return, rather than reflecting that with an else statement to check for something else. That may sound complicated, but its not, here is an example:
Do This
|
|
Not This
|
|
Figure 1 uses the end of the function to assume a positive result, exiting if this is not met as early as possible. This is pretty much always going to be preferred to Figure 2.