In this particular case, since you need to have an ANYWAY if statement, I would say that you just need to set it to zero when it reaches the count.
However, for the case when you use the value every time and just want to "wrap rounding to zero when we reach a certain value", then the case is less obvious.
If you can set n to power 2 (2, 4, 8, 16, 32 ...), then you can use the counter % n trick, the same as counter & (n-1) - which makes the operation REALLY fast.
If n not the power of two, then the likelihood that you will end up doing a real break, which is a bad idea, is very expensive to divide compared to regular instructions, and comparing and reset is probably faster than the split option.
Of course, as others have said, if your counter ever reaches the MAX limit for this type, you can have fun and games.
Edit: And of course, if you type something, it probably takes 100 times longer than division, so this is really micro-optimization if n quite large.
source share