# Coding Train Tutorial 6.2 while loop question

**URL:** <https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020>\
**Category:** Beginners\
**Created:** [December 4, 2022, 2:03pm UTC](https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020 "2022-12-04T14:03:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Siyue](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Siyue](https://discourse.processing.org/u/Siyue)\
**Post date:** [December 4, 2022, 2:03pm UTC](https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020/1 "2022-12-04T14:03:23Z")

</div>

```auto

float y=0;
float x=0;
void setup() {
  size(800, 800);
}

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

    fill(200);
    ellipse(x, y, 30, 30);
  }

```

same as the video did but just change to the y value. what’s the thing that was wrong and how will I improve the thinking structure skill or imaging code?( very beginner question, and I realize the reason I couldn’t make things right is because my "structure of problem solving " is wrong.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [December 4, 2022, 3:47pm UTC](https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020/2 "2022-12-04T15:47:44Z")

</div>

Hi @Siyue,

What are you trying to do precisely? Can you link the video / original link that you are talking about?

> [@Siyue](#):
>
> `if (mouseY<1) {`

The `mouseY` value is the `y` coordinate of the mouse in the canvas. So if your canvas is 800x800 pixels, then `mouseY` will be between 0 and (800 - 1) pixels. Therefore the above condition will rarely be true since `1` is really small. 😉

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [December 4, 2022, 4:59pm UTC](https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020/3 "2022-12-04T16:59:53Z")

</div>

> [@Siyue](#):
>
> `y=mouseY+y;`

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 4, 2022, 6:01pm UTC](https://discourse.processing.org/t/coding-train-tutorial-6-2-while-loop-question/40020/4 "2022-12-04T18:01:28Z")

</div>

Hello @Siyue 🙂

Linking the video in question to this thread for quick access for anyone with same or similar question in future: 🙃

https://www.youtube.com/embed/esKLU3dJo70?feature=oembed&wmode=opaque&list=PLzJbM9-DyOZyMZzVda3HaWviHqfPiYN7e

🤓
