I have an array and I want to scroll the positions in it backward.
I have a boolean array and I need to count how many true are there from a given cell going forward and backward.
I know that if N is the number of elements into the array, I can go ahead doing i=(i+1)%N. But what if I need to scroll it in the opposite way?
Thank you in advance.
I usually use i = (i - 1 + N) % N
to prevent negative values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With