Putting a return statement in any of the iterative statements may or may not return value. Problem with your code is that you need to provide an else condition for the cases where if condition isn't true. This is why you are getting the error.
But in case you write if/else block, each with a return statement in it then compiler then it will not force you. Thus, you need to write your code as follows: