How to re-arrange loops

Does this thread help?