Simple way to decrement number within a repeating range
Some thoughts:

(i + x) % x == i //For i &gt;= 0 &amp;&amp; i &lt; x


Then

(i + x - 1) % x


Gives us the range from 0 to x-1.
We want the range from 1 to x so we change this to:

(i + x - 2) % x + 1;


But I don't think it's particularly readable, so your ternary code might end up being better.