Well, every zig-zag in the picture is basically the same proceedure, just from a different starting point. That indicates how the outer loop should be defined, eg, the first iteration of the outer loop sets 1-3, the second sets 4-10, the third sets 11-21, etc.
Within the outer loop, it will probably be easiest to use two separate inner loops, one for traversal in each direction.
Within each inner loop, it's just a matter of incrementing the indexes appropriately and writing the next number.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.