There's no "outer loop". This is like the merge in mergesort. You look at the first element of the array and of the file. If they're equal, you do your thing and advance them both. Otherwise, you advance the smaller one and repeat.
Caution: Contents may have been coded under pressure.