# Rectangle should grow then stop (resolved)

**URL:** <https://discourse.processing.org/t/rectangle-should-grow-then-stop-resolved/4541>\
**Category:** Coding Questions\
**Created:** [October 16, 2018, 5:09pm UTC](https://discourse.processing.org/t/rectangle-should-grow-then-stop-resolved/4541 "2018-10-16T17:09:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![singenya](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@singenya](https://discourse.processing.org/u/singenya)\
**Post date:** [October 16, 2018, 5:09pm UTC](https://discourse.processing.org/t/rectangle-should-grow-then-stop-resolved/4541/1 "2018-10-16T17:09:14Z")

</div>

hello, i’m a beginner on processing and I want to make something simple but I don’t really understand why it don’t work.

here’s my code :

```auto
void setup()
{
  size(600, 600);
  background(255);
}

void draw()
{
  for (int a = 0; a<width; a+=1)
  {
    rect(100, 100, a, 100);
    if (a>450)
    {
      a+=0;
    }
  }
}

```

what i want it to do is draw a rectangle that get larger (fro left to right) and when this rectangle get  
close to the width of the window it stop growing and it stay in this position.  
actually i managed to make it growing but when i put the “if” and what’s in it start already grown untill outside and it don’t work.  
thanks for your help.

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [October 16, 2018, 5:24pm UTC](https://discourse.processing.org/t/rectangle-should-grow-then-stop-resolved/4541/2 "2018-10-16T17:24:43Z")

</div>

The image your sketch is drawing is only updated and shown to the user when the `draw()` function is finished. Your entire loop happens in each frame, and at the end of that loop, the rectangle is already long.

What you need to do is this:

```auto
int a = 0;

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

void draw() {
  background(255);
  if (a<450) {
    a++;
  }
  rect(100, 100, a, 100);
}

```

Notice that this will cause a small rectangle to be drawn the first time draw() finishes, and a larger one the next time. And so on.

---

<div class="post-metadata">

**Author:** ![singenya](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@singenya](https://discourse.processing.org/u/singenya)\
**Post date:** [October 16, 2018, 5:30pm UTC](https://discourse.processing.org/t/rectangle-should-grow-then-stop-resolved/4541/3 "2018-10-16T17:30:01Z")

</div>

thank you it’s working perfectly as I wanted !
