Won't this make j point to a future index? This could have the possible side effect of skipping some parts of the array from analysis (if you have two resources added one after the other, the second one may be skipped). To ensure visiting all elements you would have to do j = currLoc; after the array (and then transform the for loop into a do while)