I am trying to increase the number based on click. How the click occurs does not matter, so I will adhere to the logic. I am doing this in Java, but the logic should be the same.
int index = 0;
index = (index + 1) % arrySize;
With this logic, every time the user clicks, it indexwill increase by 1. Then it modulo arrySizecauses it indexto return to 0 when it indexmatchesarrySize
(10% 10 will force the index to return to 0). This is great because it looks like a loop that goes from 0 to 10, and then back to 0 and no more than 10.
I try to do the same logic, but back
where, based on the click, the number will decrease and go down to 0, then it returns to arrySizeinstead-1
How can I achieve this logic?