How to golf wrap-around assignments?
Try the following, it ensures x to be inside [0, n] (say n = 5), only when x &gt; -n and x &lt; 2n.

x = (5 + x) % 5

Thanks to ovs!
Try it online!

As mentioned by xash in the comments, if you want to make it work for any x, then do
x = ((x % 5) + 5) % 5

Try it online!