# Repetitive code

**URL:** <https://discourse.processing.org/t/repetitive-code/19659>\
**Category:** Coding Questions\
**Created:** [April 11, 2020, 1:21pm UTC](https://discourse.processing.org/t/repetitive-code/19659 "2020-04-11T13:21:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quorum](https://avatars.discourse-cdn.com/v4/letter/q/ad7895/32.png) [@Quorum](https://discourse.processing.org/u/Quorum)\
**Post date:** [April 11, 2020, 1:21pm UTC](https://discourse.processing.org/t/repetitive-code/19659/1 "2020-04-11T13:21:50Z")

</div>

Good morning everyone,  
I just started using processing.  
I’m drawing a sketch where I’m going to create 30 little balls.  
There’s a way to make them appear in sequence without writing 30 times the same line with the ellipse?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 11, 2020, 1:32pm UTC](https://discourse.processing.org/t/repetitive-code/19659/2 "2020-04-11T13:32:27Z")

</div>

Hello,

> **[for / Reference](https://processing.org/reference/for.html)**
>
> Controls a sequence of repetitions. A basic for structure has three parts: init, test, and update. Each part must be separated by a semicolon (;). The loop continues until …

`:)`

> **Resources**
>
> I encourage you to review the resources available here:
> 
> - Processing website has references, examples, tutorials, etc.  
> [https://processing.org/](https://processing.org/)
> - Those available with the Processing PDE (IDE).  
> An exploration of the tabs will reveal what is available; there are libraries and examples there.
> - The Processing Foundation  
> [https://processingfoundation.org/](https://processingfoundation.org/)  
> Check out the tabs.  
> In the education tab, there is a reference to the Coding Train.
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [Processing Tutorials - Happy Coding](https://happycoding.io/tutorials/processing/)

---

<div class="post-metadata">

**Author:** ![Quorum](https://avatars.discourse-cdn.com/v4/letter/q/ad7895/32.png) [@Quorum](https://discourse.processing.org/u/Quorum)\
**Post date:** [April 11, 2020, 6:15pm UTC](https://discourse.processing.org/t/repetitive-code/19659/3 "2020-04-11T18:15:27Z")

</div>

Very Nice! Thank you 🙂

---

<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:** [April 11, 2020, 6:40pm UTC](https://discourse.processing.org/t/repetitive-code/19659/4 "2020-04-11T18:40:09Z")

</div>

you can also work with arrays (lists) and the for loop over the arrays (see tutorial)

for example first array x[], then y[] then speedX[] and speedY[]

so the properties of ONE ball is in the arrays in the same line each.(one ball properties in each array, in the same line)

- ball 0 in line 0 of all arrays, ball 1 in line 1 of all arrays

```auto
for(int i........) {
    ellipse(x[i], y[i], 7,7);
    x[i] = x[i] + speedX[i];
    y[i] = y[i] + speedY[i];
}

```

---

<div class="post-metadata">

**Author:** ![Quorum](https://avatars.discourse-cdn.com/v4/letter/q/ad7895/32.png) [@Quorum](https://discourse.processing.org/u/Quorum)\
**Post date:** [April 12, 2020, 2:32pm UTC](https://discourse.processing.org/t/repetitive-code/19659/5 "2020-04-12T14:32:34Z")

</div>

I’ll try it today 🙂  
Thank you very much 🙂
