# Change variable every other loop

**URL:** <https://discourse.processing.org/t/change-variable-every-other-loop/32212>\
**Category:** Coding Questions\
**Created:** [September 12, 2021, 8:54am UTC](https://discourse.processing.org/t/change-variable-every-other-loop/32212 "2021-09-12T08:54:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [September 12, 2021, 8:54am UTC](https://discourse.processing.org/t/change-variable-every-other-loop/32212/1 "2021-09-12T08:54:18Z")

</div>

how do i make i3 equal 1, then make it equal 8 in the loop after, 1 again in the loop after and so forth?

---

<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:** [September 12, 2021, 9:14am UTC](https://discourse.processing.org/t/change-variable-every-other-loop/32212/2 "2021-09-12T09:14:27Z")

</div>

```auto
// start with i3 = 1
i3 = 1;
// When you want to flip value
i3 = 9 - i3;

```

---

<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:** [September 12, 2021, 9:44am UTC](https://discourse.processing.org/t/change-variable-every-other-loop/32212/3 "2021-09-12T09:44:07Z")

</div>

Hello,

Get to know the Modulus (Modulo) operator:

- [What is the Modulus Operator? A Short Guide with Practical Use Cases | Matthew J. Clemente](https://blog.mattclemente.com/2019/07/12/modulus-operator-modulo-operation/)
- [https://processing.org/reference/modulo.html](https://processing.org/reference/modulo.html)

Example:

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

You can look up `frameCount` in the references; this can be any counter in your code.

`:)`
