Loops Assessment


Loops review

for (let i = 0; i < width; i++) {

}

Worksheet and Assignment review

let cols = 10;
let rows = 10;

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  for (let r = 0; r < 10; r++) {
    for (let c = 0; c < 10; c++) {
      if (r % 2 == 0 && c % 2 == 0) {
        fill(0);
      } else if (r % 2 == 1 && c % 2 == 1) {
        fill(0);
      } else {
        fill(255);
      }
      rect(
        (c * width) / cols,
        (r * height) / rows,
        width / cols,
        height / rows
      );
    }
  }
}

https://editor.p5js.org/icm-nun/full/5qzKVtgBp

<aside> ✏️

Test yourself (loops)

</aside>