I would create 4 separate loops.
Loop 1 would create 1 2 3 4 5
Loop 2 would create 6 7 8 9
Loop 3 would create 10 11 12 13
Loop 4 would create 14 15 16
When this is done, you've filled out the outside of the square, and are left with a smaller, 3x3 square inside, which can be filled in exactly the same way, with exactly the same 4 loops.