# Why doesn't FOR-EACH give every output a different VALUE from ARRAY?

**URL:** <https://discourse.processing.org/t/why-doesnt-for-each-give-every-output-a-different-value-from-array/33987>\
**Category:** Beginners\
**Created:** [December 7, 2021, 1:09pm UTC](https://discourse.processing.org/t/why-doesnt-for-each-give-every-output-a-different-value-from-array/33987 "2021-12-07T13:09:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![badbatman](https://avatars.discourse-cdn.com/v4/letter/b/da6949/32.png) [@badbatman](https://discourse.processing.org/u/badbatman)\
**Post date:** [December 7, 2021, 1:09pm UTC](https://discourse.processing.org/t/why-doesnt-for-each-give-every-output-a-different-value-from-array/33987/1 "2021-12-07T13:09:32Z")

</div>

I made an array that I output in a loop. But every item I assign the array it keep giving the same value while I’ve put 4 values into the array. I’ve tried everything but it keeps giving the same value (330). I have also made use of a for loop but it gives the same results. Thank you.

```auto
  int[] sx = {330,390,335,345};
  
  for (int i : sx){
    copy(video, i, 170, 40, 40, 0, 0, video.width/4, video.height/4);
    
    copy(video, i, 170, 40, 40, 150, 150, video.width/4, video.height/4); 
    
    copy(video, i, 205, 40, 40, 300, 300, video.width/4, video.height/4);
    
    copy(video, i, 230, 60, 40, 400, 150, video.width/4, video.height/4);
    print(i);
  }

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0e1119b1ff7bcb7a9d61c29db36c6ad42381ed47.png)  
When I used print to see the output of the value it always starts with 330, is that the problem?

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [December 7, 2021, 2:32pm UTC](https://discourse.processing.org/t/why-doesnt-for-each-give-every-output-a-different-value-from-array/33987/2 "2021-12-07T14:32:20Z")

</div>

It is not clear what you are trying to do and your explanation as to the problem doesn’t help.

If you try

```auto
int[] sx = {330, 390, 335, 345};

for (int i : sx) {
  println(i);
}

```

you get the following output

```auto
330
390
335
345

```

which is exactly what you would expect.

So in your code you have 4 copy statements which are executed for each integer in the array. If we expand your code to remove the loop and shaow what is actually being executed we get

```auto
int i;

i = 330;
copy(video, i, 170, 40, 40, 0, 0, video.width/4, video.height/4);
copy(video, i, 170, 40, 40, 150, 150, video.width/4, video.height/4); 
copy(video, i, 205, 40, 40, 300, 300, video.width/4, video.height/4);
copy(video, i, 230, 60, 40, 400, 150, video.width/4, video.height/4);
print(i);

i = 390;
copy(video, i, 170, 40, 40, 0, 0, video.width/4, video.height/4);
copy(video, i, 170, 40, 40, 150, 150, video.width/4, video.height/4); 
copy(video, i, 205, 40, 40, 300, 300, video.width/4, video.height/4);
copy(video, i, 230, 60, 40, 400, 150, video.width/4, video.height/4);
print(i);

i = 335;
copy(video, i, 170, 40, 40, 0, 0, video.width/4, video.height/4);
copy(video, i, 170, 40, 40, 150, 150, video.width/4, video.height/4); 
copy(video, i, 205, 40, 40, 300, 300, video.width/4, video.height/4);
copy(video, i, 230, 60, 40, 400, 150, video.width/4, video.height/4);
print(i);

i = 345;
copy(video, i, 170, 40, 40, 0, 0, video.width/4, video.height/4);
copy(video, i, 170, 40, 40, 150, 150, video.width/4, video.height/4); 
copy(video, i, 205, 40, 40, 300, 300, video.width/4, video.height/4);
copy(video, i, 230, 60, 40, 400, 150, video.width/4, video.height/4);
print(i);

```

the copy function is executed 16 times.

---

<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 8, 2021, 8:17pm UTC](https://discourse.processing.org/t/why-doesnt-for-each-give-every-output-a-different-value-from-array/33987/3 "2021-12-08T20:17:08Z")

</div>

One remark

Processing doesn’t update the screen throughout

So when you expect to see the changes that happen inside the for loop you won’t see it.

Is this your issue?
