These two concepts are a little easy to mix up. My understanding is that for is a loop function, while while is a special kind of if statement that keeps looping as long as the condition is true.
Using the exercises from Worksheet 4, I added a colorful checkerboard background and also made a flashing disco ball. I wanted to imitate the background from “Room on Fire,” but I’m too tired to think straight right now, so maybe I’ll work on it in a couple of days…

(Room on fire🔼)
The first row of my grid never works, and I have no idea why.
Here is my code:
//grid
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
for(i=0;i<=400;i+=40){
for(y=0;y<=400;y+=40){
rect(i,y,40,40);
noFill();
if(mouseX>=i&&mouseX<i+40&&mouseY>=y&&mouseY<y+40){
fill(255,0,0);
}
}
}
}