# Array with 2 of the same value

**URL:** <https://discourse.processing.org/t/array-with-2-of-the-same-value/4892>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 26, 2018, 7:35am UTC](https://discourse.processing.org/t/array-with-2-of-the-same-value/4892 "2018-10-26T07:35:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [October 26, 2018, 7:43am UTC](https://discourse.processing.org/t/array-with-2-of-the-same-value/4892/2 "2018-10-26T07:43:57Z")

</div>

Hi,

Please, edit your post and format your code. It is all explained here: [Guidelines—Tips on Asking Questions](https://discourse.processing.org/t/guidelines-tips-on-asking-questions/2147)  
**EDIT:** Thanks 🙂

The problem with your code is that your are looping one increment at a time so even if inside your loop you assign the 2 same values you erase that value in the second increment. Since example speaks more than words:

- First loop: i = 0
  - kaartSets[0] = 0
  - kaartSets[1] = 0

Everything is ok here but look what happens in the second loop:

- Second loop: i = 1 -\> Only one increment:
  - kaartSets[1] = 1
  - kaartSets[2] = 1

Now you start to mess things up because you are changing the value of the element [1].

Now, you have several way to achieve what you want to do, here’s one:

```auto
int [] cardSets = new int[amountOfSets];
int value = 0

void cardSetsArray() {
  for(int i = 0; i < cardSets.length -1; i+=2) {
    cardSets[i] = value;
    cardSets[i + 1] = value;
    value++;
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/array-with-2-of-the-same-value/4892)._
