Adobe After Effects ForumConvert increasing variable to looping variable
Convert increasing variable to looping variable
by Mike Foran on Jan 11, 2019 at 7:14:55 pm

I'm trying to write an expression that converts a constantly increasing variable, like time, to a looping variable. Kind of like the 'linear' function but instead of clamping the value translation to either end of the range, it would loop the variable back around to the beginning again. I've written this looping expression, but it doesn't really allow me to set the range of output values, it just cycles the variable every 10 seconds from 0 to 10. I also feel like there's a better way to do this that I am not aware of.

```t = time; t = time; v = t; i = 0; End = 10 if (t>End){ i = Math.floor(t/End); v = t - (i*End); } [v];```

Re: Convert increasing variable to looping variable
by Walter Soyka on Jan 11, 2019 at 7:22:17 pm

Use the modulus operator -- it returns the division remainder:

`time % 10`

Walter Soyka
Motion Graphics, Widescreen Events, Presentation Design, and Consulting

Re: Convert increasing variable to looping variable
by Mike Foran on Jan 11, 2019 at 8:03:29 pm

Exactly! I knew there had to be a simpler method than what I was doing. Thank you.

Re: Convert increasing variable to looping variable
by Jeff Kay on Jan 11, 2019 at 10:11:01 pm

The one I've been using is
`Math.floor(time*Y)%X`

Where it increments Y times a second and counts from 0 to X-1.