cycle negatively through values of a variable
in
Programming Questions
•
5 months ago
Hi!
Well, this might be a really easy one to solve, but for the life of me, I can't figure it out.
Let's say you have a variable int c = 0. You go c++ through every iteration of a loop, and you want it to loop back to 0 when you reach, say, 200. So doing this is easier:
c = (c+1) % 200;
Is there an equivalent, simple way to loop when you're
substracting from it, without having to do something like
if (c > 0){
c--;
}else{
c = 200;
}
In other words: if the value is 0, and it goes down 1, I want it to go back to the max value (in this case, 200).
Thanks for all your help!
1