Change line() color in a nested while-loop

@Whahahahaha

Thank you! it works indeed :slight_smile:

I added the โ€˜whileโ€™ loop that I needed for my assignment to it :slight_smile:

while (x < stop) {
        
        stroke(0);
        
        if (x == 40 || x == 60) {
        stroke(255);
        }
        
    line(x, 60, x, 80);
    x += stap;
        
    }
}

and got the desired effect I was looking for :).

Sorry if the question is stupid, but could you tell me why I cannot put the

line(x, 60, x, 80);
x += stap;

right under the x<stop equation, and before the if (x== 40 โ€ฆ)

like:

while (x < stop ) {

stroke(0);
line(x, 60, x, 80);
    x += stap;

   if (x == 40 || x == 60) {
      stroke(255);
    }
  }
}

it just seems like it is in the same position either way (as in being inside the while loop) but just getting added later. Or does it need to do the equation/counting first before it should draw?

1 Like