Condense these loops into a single loop.