By formatting i mean, make the code readable in the Post. Just add the code inside this :
/```
/```
Just without /. You can get this by pressing </> in the top Selection When you write a comment.
And to get the right pattern, you just Need 2 Loops. In one you have to iterate over the rows you want, and in the one inside you Need to set the number of times it has to iterate to the current iteration of the first loop.