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
x = m - abs(i % (2*m) - m)