In this quick-tip we show you how to work with loops inside After Effects. By following our explanation you should be able to replicate the following animation in under 2 minutes.

As most of you might already know, After Effects does not offer a loop property or function – you have to write your own expressions in order to loop keyframes. To do so, it supports two different functions: loopIn and loopOut.
loopIn("type", keyframes);
loopOut("type", keyframes);
While loopIn loops the number of keyframes you passed BEFORE your first keyframe, loopOut takes care of all after the last keyframe.
The parameter type accepts different types of loops, read about them here. The only two we are looking at right now are cycle (the normal one) and pingpong (forward and reverse). So if you wanted to loop your animation, you would basically use this:
loopOut("cycle", 0);
// parameter 0 tells AE to use all keyframes it can
// find since it is impossible to loop 0 keyframes...
Unfortunately we are missing a parameter to determine how often we want our range of keyframes to loop – we have to do it ourselves. Let’s say we have an animation within the position property and want to loop it twice.
var loops = 2; // loop it two times
var range = key(numKeys).time - key(1).time; // length of our range
(time > key(1).time + range * (loops + 1)) ? transform.position : loopOut("cycle", 0);
This chiefly compares the actual time with the number of loops we want to happen and decides whether to display a loop or just the last position value.
When animating bouncing objects for example we build a simple loop and then alter the loops in order to make the object lose speed. The cool thing about those loops is that you can modify your keyframes value- and timewise without any side-effects – and if you need to make changes on a particular loop it works quite simple: choosing Animation > Keyframe Assistent > Convert Expressions to Keyframes you can bake those animations into editable keyframes…
Jake & Dan

Excellent to know this while I learn AE this Summer. Thanks Dan and Jake!