Profile lookup looping problem

try going through your code step by step, what happens if this is true for the first element in the array?