Instead of computing a ret value, you should return the result as soon as you find it. This makes the code more readable since you need one local variable less and the conditions in your for-loops are simplified (they don't need to check if the result was found already).