This is probably a very basic question but I just can't work out how to find the answer after trying more then a few times.
How can I create a variable so that it loops within a certain range, even if I add or subtract more then the range?
Say I want "int i" to be equal to 0-3, but in my code I have several nested loops and I want to increment "i" several times? I want it to return to 0 if I increment past 3, and i want it to go to 3 if I decrement below 0.
i've used at the end of a loop if it increments just once once, but what if I increment it 3 or 4 times in the loop? Also that doesn't work for the decrement condition. There must be an easier way then having an if statement after each increment?
something like
Code:
a_array[i++] = b_array[i];
if (i>2){i=0};
a_array[i++] = b_array[i];
if (i>2){i=0};
a_array[i++] = b_array[i];
if (i>2){i=0};
This is just awful, I suspect there's an easy answer but no luck finding it.
Out of desperation I did it once using another array like a[0,1,2,3,0,1,2,3,0,1,2,3], this lets me increment a few times before having to use an "if" statement like above, but I suspect this would get laughed at too.
Sorry for the noob question, even just a pointer to a tutorial or a hint what to google would be great, thanks very much.