In a similar way that modulo generates a sawtooth wave. It doesn\'t have to be continuous.
here is what i mean:
int m = 10; int x = 0; int i
Try this:
x = m - abs(m - 2*(i++ % m))