# Beginner's problem with while() loop

**URL:** <https://discourse.processing.org/t/beginners-problem-with-while-loop/26469>\
**Category:** Coding Questions\
**Created:** [December 23, 2020, 12:15pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469 "2020-12-23T12:15:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nazazaku](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nazazaku](https://discourse.processing.org/u/nazazaku)\
**Post date:** [December 23, 2020, 12:15pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/1 "2020-12-23T12:15:54Z")

</div>

I just want to do a simple grid with circles, but it just doesn’t work. The circles don’t complete the grid and stop at a random point. The circles stop at a different point each time I run the program. Pls help.  
I’m using 3.5.4 btw.

```auto
float x = 0;
float y = 0;
boolean a = true;

void setup()
{
  size(800, 800);
}

void draw()
{
  background(0);
  
  while(a)
  {
    ellipse(x, y, 50, 50);
    
    x= x+100;
    
    if(x > width)
    {
      y = y + 100;
      x = 0;
    }
    
    if(y > height)
    {
       y=0;
    }
    
    
    println("x", x, "y", y);
  }

   
   
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 23, 2020, 1:02pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/2 "2020-12-23T13:02:33Z")

</div>

a never gets false

what about

while(y\<height) …

> [@nazazaku](#):
>
> ```auto
> if(y > height)
> {
> y=0;
> }
> 
> ```

And get rid of this

---

<div class="post-metadata">

**Author:** ![nazazaku](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nazazaku](https://discourse.processing.org/u/nazazaku)\
**Post date:** [December 23, 2020, 2:01pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/3 "2020-12-23T14:01:41Z")

</div>

Not working :(, the grid appears for a frame and disappears forever. But still thx!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 23, 2020, 2:29pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/4 "2020-12-23T14:29:23Z")

</div>

> [@nazazaku](#):
>
> ```auto
> if(y > height)
> {
> y=0;
> }
> 
> ```

That’s right.

Place these lines AFTER the while loop

Hey and welcome to the forum!

Great to have you here!

Warm regards,

Chrisir

**Example**

```auto

float x = 0;
float y = 0;

void setup()
{
  size(800, 800);
}

void draw()
{
  background(0);

  while (y <= height)
  {
    ellipse(x, y, 50, 50);

    x = x+100;

    if (x > width)
    {
      y = y + 100;
      x = 0;
    }

    println("x", x, "y", y);
  }// closing while loop 

  // reset 
  x=0;
  y=0;
}//closing function draw() 
//

```

---

<div class="post-metadata">

**Author:** ![nazazaku](https://avatars.discourse-cdn.com/v4/letter/n/5daacb/32.png) [@nazazaku](https://discourse.processing.org/u/nazazaku)\
**Post date:** [December 23, 2020, 3:46pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/5 "2020-12-23T15:46:25Z")

</div>

Thx for the help!!!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [December 23, 2020, 9:29pm UTC](https://discourse.processing.org/t/beginners-problem-with-while-loop/26469/6 "2020-12-23T21:29:35Z")

</div>

You are welcome!

Chrisir
