I'm trying to cycle an integer between a minimum and maximum value inside of a range, e.g., 0-2, so that if I increment or decrement the value, it's always inside the range. Anything over maximum should snap to minimum, and anything below minimum should snap to maximum. The following code works fine for incrementing, but not for decrementing:
current=(current+1)%(maximum+1);
Is there a similar trick that would work for decrementing, too?