Hey Ed,
The way nested for
loops work is basically this: for each time you run through the outside loop (row) you run ALL inside loops (column). So to make things simple let's assume you wanted to draw a 3x3 grid.
for row in 1...3 {
for column in 1...3 {
// column stuff here
}
}
So when row
= 1, it then goes through all 3 columns and draws them accordingly. When that is finished, moves to the next iteration of row
= 2, then again goes through all 3 columns. And so on, until all rows have been completed.
A loop operates on the principle that ALL code within it has to complete before it moves to the next iteration.
So in the project, we are essentially drawing 1 row at a time. until we have the desired amount.
As for startX, you are basically on the horizontal axis. So you account for the width of each column. And that gives the initial x point for each square.
startY is on the vertical axis, so we account for the width of each row. which gives us the initial y point for each square.