# modulo with n instead of 0 without using if-statement

Is there a way to to express the following without using an if statement, but with mathematical operations instead?

{ 5 if x % 5 = 0, x % 5 otherwise }

• Mod[x-1,5]+1? – mikado Oct 28 '19 at 23:19

You can use the 3rd offset argument of Mod for this:
Mod[x, 5, 1]

The 3rd argument effectively shifts the point where Mod loops back. So Mod[x, 5, 0] loops from 0 to 4 and Mod[x, 5, 1] loops from 1 to 5.