Your error is because it checks the second element in the array, it doesn't contain entry so it sets the flag to false, then it checks the second element for bob, which it does contain, it sets the flag to true, then it performs the condition test outside the inner loop and returns true. If the first element doesn't exist, should you check the second?