# Simple ArrayIndex problem

**URL:** <https://discourse.processing.org/t/simple-arrayindex-problem/19434>\
**Category:** Beginners\
**Created:** [April 5, 2020, 3:20pm UTC](https://discourse.processing.org/t/simple-arrayindex-problem/19434 "2020-04-05T15:20:20Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 13, 2020, 6:31am UTC](https://discourse.processing.org/t/simple-arrayindex-problem/19434/7 "2020-04-13T06:31:01Z")

</div>

If you want to iterate over pairs of vertices in a closed shape, you can also use modulo %.

```auto
for (int i=0; i<pos.size(); i++) {
   a = pos.get(i);
   b = pos.get( (i+1)%pos.size() );
}

```

This works for any size. For a size of 3, this will generate:

> 0,1 – 1,2 – 2,0

---

_[View the full topic](https://discourse.processing.org/t/simple-arrayindex-problem/19434)._
