I am doing a small assignment that requires the following:
I have to create a while-loop that draws 30 lines on-screen. Line number 7 and line number 23 should be colored red.
Because I am still trying to figure things out, I try to color the 2 nearest lines from stroke(0); to stroke(255);, but no matter what I try, I cannot get the 2 lines to change color
In this example I tried nesting a while loop, which so far doesn't work. I also tried removing the nested while loop and add an "if" statement with the same variables (x == 40 && x == 60) but still nothings happens. What can I do to fix this?
var x = 20;
var stap = 20;
var stop = 600;
function setup () {
createCanvas(700, 700);
}
function draw () {
stroke(0);
while(x < stop) {
line(x, 60, x, 80);
x += stap;
while (x == 40 && x == 60) {
stroke(255);
}
}
}
while (x == 40 && x == 60)
means that the loop keeps running es longx==40
andx==60
. Sincex
can't have 2 different values at the same time, the condition is never fulfilled. This means the body of the loop is never executed.