if only a few are skipped, then you could have [Record ID#]-2 and another relationship. Then on each record you have a formula checkbox field set to true. called [Parent Exists?]
Look that up to the child.
Then you have a formula field that is [Record ID - x (final)] which uses the value in [Record ID#]-1 if the first relationship found a parent, else [Record ID#]-2 if it did not. of course, you could continue this pattern up to even say 10 records back.
Then use the (final) field to have the "real" relationships and do your lookup fields just once from that relationship. So the other relationships are there just to figure out the correct parent to use in the (final) relationship.
So no looping. Quick Base does not loop in a traditional sense of my Fortran days
Do I = 1,10
.
.
.
Continue