How do these cycles?

Here, there is such code:

var size = 8;

var board = "";

for (var y = 0; y < size; y++) {
 for (var x = 0; x < size; x++) {
 if ((x + y) % 2 == 0)
 board += " ";
else
 board += "#";
}
 board += "\n";
}

console.log(board);


I'm a little confused why it works "as necessary";the for loop add +1. That is, they work only 8 times, but srabatyvaet it more.
Code
if ((x + y) % 2 == 0)
 board += " ";

would work every second time
Pliz explain
July 9th 19 at 12:49
1 answer
July 9th 19 at 12:51
Solution
Cycles are nested. Each performed 8 times, i.e. 8*8=64 iterations
That is, we have : first cycle y+1 nested x work +8, then y +2, x restarts and again +8 and y is 8? - krista.Eichma commented on July 9th 19 at 12:54
: Exactly - Kameron_Hilpert34 commented on July 9th 19 at 12:57
with each iteration of the loop, Y has size of loop iterations X - Kameron_Hilpert34 commented on July 9th 19 at 13:00
: thank you very much - krista.Eichma commented on July 9th 19 at 13:03
: not at all - Kameron_Hilpert34 commented on July 9th 19 at 13:06
: a chicken breast in the mail for you skins) - krista.Eichma commented on July 9th 19 at 13:09

Find more questions by tags JavaScript