Coding Train Tutorial 6.2 while loop question

Also this will cause y to get very big very quickly

You need to ba able to see the values of x and y as the program runs add the statement
println(x,y); inside the draw() method like this

void draw()
{
  background(200, 20, 90);
 
  y=0;
  while (y<height) {
      if (mouseY<1) {
        y=y+1;
      } else {
        y=mouseY+y;
      }
    }
    println(x,y);  // see what is happening

It should help you find the mistakes in your code logic.

1 Like