# If statement in arrays

**URL:** <https://discourse.processing.org/t/if-statement-in-arrays/29454>\
**Category:** Coding Questions\
**Created:** [April 17, 2021, 5:53pm UTC](https://discourse.processing.org/t/if-statement-in-arrays/29454 "2021-04-17T17:53:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henryM](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@henryM](https://discourse.processing.org/u/henryM)\
**Post date:** [April 17, 2021, 5:53pm UTC](https://discourse.processing.org/t/if-statement-in-arrays/29454/1 "2021-04-17T17:53:56Z")

</div>

So I am making a prototype for my game to try and demonstrate what I am trying to do.

[https://editor.p5js.org/henhog123/sketches/B0QwRqpXj](https://editor.p5js.org/henhog123/sketches/B0QwRqpXj)

In the editor, you can see only one circle moves but I want all the circles to move. This is probably the wrong way to do things but its the way I came up with, so can someone help me out.

---

<div class="post-metadata">

**Author:** ![henryM](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@henryM](https://discourse.processing.org/u/henryM)\
**Post date:** [April 17, 2021, 6:11pm UTC](https://discourse.processing.org/t/if-statement-in-arrays/29454/2 "2021-04-17T18:11:09Z")

</div>

I have made an improvement to the code but i still am having the same problem

[https://editor.p5js.org/henhog123/sketches/B0QwRqpXj](https://editor.p5js.org/henhog123/sketches/B0QwRqpXj)

---

<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:** [April 17, 2021, 6:22pm UTC](https://discourse.processing.org/t/if-statement-in-arrays/29454/3 "2021-04-17T18:22:57Z")

</div>

Hi,

Welcome to the forum! 😉

> Pro tip : in the p5 web editor you can auto format your code by going into Edit → Tidy Code

Your code doesn’t work because when you are calling in the `draw()` function :

```auto
for (let i = 0; i < 3; i++) {
  bubbles[i].move();
  bubbles[i].show();
}

```

Then as soon as the `round` variable has the value `100`, you start checking the `bubbles[0]` object in the array and it’s calling its `move()` method :

```auto
move() {
  if (round == 100) {
    this.x = random(24, 376);
    this.y = random(24, 376);
    round = 0;
  }
}

```

But here the condition is true and the `round` variable gets reset to `0` so when you are trying to move the next circle it’s no more `100` and it only moves the first circle!!

What you can use is the [`frameCount`](https://p5js.org/reference/#/p5/frameCount) variable that is counting the number of frames since the beginning of the sketch and it’s exactly what you are doing! 😋

---

<div class="post-metadata">

**Author:** ![henryM](https://avatars.discourse-cdn.com/v4/letter/h/7ab992/32.png) [@henryM](https://discourse.processing.org/u/henryM)\
**Post date:** [April 17, 2021, 6:38pm UTC](https://discourse.processing.org/t/if-statement-in-arrays/29454/4 "2021-04-17T18:38:39Z")

</div>

thank you so much it now works great!!
