When coding, use the modulo to loop something over time

I recently started playing around with the app Pico-8 in an effort to better understand how animation can be created purely through code. It's been challenging, especially because I'm creating animations with code that doesn't exceed Twitter's 280 character limit.

One thing I learned while making my last Pico-8 animation is the power of the modulo, which is typed in code using the percent sign (%). In programming, this operator returns the remainder after dividing one integer by another. For example, 8 % 4 would return a value of 0 (because 8 divided by 4 equals exactly 2). 8 % 3 would return a value of 2 (because 8 divided by 3 gives you a quotient of 6 and leaves you with a remainder of 2).

In practice, I found that the modulo is really useful for looping something over and over while time continues to increase forever. Here's an animation, and its code, that uses this concept:

cls()
camera(-33,-33)
for t=0,159 do
    a,b=(t%2)*32,flr(t/2)
    c,d=(t%4)*16,flr(t/4)
    e,f=(t%8)*8,flr(t/8)
    g,h=(t%16)*4,flr(t/16)
    i,j=(t%32)*2,flr(t/32)
    if b<64 then
        line(a,b,a+31,b,1)
    end
    line(c,d,c+15,d,2)
    line(e,f,e+7,f,14)
    line(g,h,g+3,h,7)
    line(i,j,i+1,j,13)
    flip()
end

In the bolded code, you can see that the variable t is being . . . moduloed? . . . by five different values (2, 4, 8, 16, 32). The variable t represents time, and it increases by 1 every time the for function is called (which happens 30 times a second in Pico-8). So if I wanted to have something loop every second, I would use the equation t % 30 in order to get a value that is looping once every 30 frames, and then I would modify that value as necessary.

In this example, I am using the modulo to change the x position of different horizontal lines, and have them loop at different rates.