# Loops using arrays

**URL:** <https://discourse.processing.org/t/loops-using-arrays/30253>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 24, 2021, 6:58pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253 "2021-05-24T18:58:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [May 24, 2021, 6:58pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/1 "2021-05-24T18:58:23Z")

</div>

what is wrong with this code? Why does not the ellipses change colors?  
\<  
color c[];  
int x = 0;

void setup() {  
size(400,400);  
c[0]=color(255, 0, 0); // first color  
c[1]=color(0, 255, 0); // second  
c[2]=color(0, 0, 255); // third  
}  
void draw() {

```
int j = 20;

```

for (int i = 40; i \<= 500; i = i+80 ) {  
fill(c[x])  
ellipse(i,100,30,80);  
x = x + 1;  
}  
\>

---

<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:** [May 24, 2021, 7:15pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/2 "2021-05-24T19:15:56Z")

</div>

```auto

color[] c = new color[3];
int x;

void setup() {
  size(400, 400);
  c[0]=color(255, 0, 0); // first color
  c[1]=color(0, 255, 0); // second
  c[2]=color(0, 0, 255); // third
}

void draw() {

  int j = 20;
  x = 0;

  for (int i = 40; i <= 500; i = i+80 ) {
    fill(c[x]);
    ellipse(i, 100, 30, 80);
    x = x + 1;
    if (x>2) { 
      x=0;
    }//if
  }//for
}//func

```

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [May 24, 2021, 7:19pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/3 "2021-05-24T19:19:46Z")

</div>

thank you! Im also wondering what new color[3]; does

---

<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:** [May 24, 2021, 9:07pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/4 "2021-05-24T21:07:54Z")

</div>

This just makes an array with 3 empty slots

---

<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:** [May 25, 2021, 2:23pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/5 "2021-05-25T14:23:35Z")

</div>

Hello,

In the Processing software menu select File \> Preferences…  
And check the box for _Continuously check for errors_ and _Show Warnings_:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7ac75e7db65d367fed7ccefa6eac254fa814786f.png)

When I ran your code it had some obvious errors that you could have easily corrected.

First error:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1df580103e5de8e3f8c308038ecef9f498e3480e.png)

And so on…

`:)`

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [May 25, 2021, 2:34pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/6 "2021-05-25T14:34:48Z")

</div>

I have managed to fix it but what program or thing are your using to write code? The place I write it it also corrects code but its written too complicated to understand compared to the response you are getting.

---

<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:** [May 25, 2021, 2:39pm UTC](https://discourse.processing.org/t/loops-using-arrays/30253/7 "2021-05-25T14:39:56Z")

</div>

> [@Kenga123456](#):
>
> what program or thing are your using to write code?

Using this thing:  
_[Download Processing / Processing.org](https://processing.org/download/)_

What thing are you using?

`:)`

---

<div class="post-metadata">

**Author:** ![Kenga123456](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@Kenga123456](https://discourse.processing.org/u/Kenga123456)\
**Post date:** [August 9, 2021, 9:43am UTC](https://discourse.processing.org/t/loops-using-arrays/30253/8 "2021-08-09T09:43:06Z")

</div>

> [@glv](#):
>
> Download \ Processing.org

i’m late but it is called openprocessing and I can’t download the processing you are showing because I am using a chromebook.

---

<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:** [August 9, 2021, 10:13am UTC](https://discourse.processing.org/t/loops-using-arrays/30253/9 "2021-08-09T10:13:05Z")

</div>

Hello,

In place of `println()` you can use `console.log()`:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/652de65ea3daf6b334dcaab65f40a5f33c93f6a3.png)

I converted C and F to strings so I could put them on one line.

`:)`
