Then it sounds like the original function is flawed, because what I proposed would seem to work fine for the loop posted, since it would increment i or decrement it and pass it along for the next recursion loop. It compares i (or mid, after it was incremeneted or decremented) to the value that's being searched for.