The loop in and loop out functions allow you to repeat, mirror, and continue keyframed animations.
A loop function starts with the name "loopIn" or "loopOut"
with only the second word's first character capitalized.
This is followed by an open parenthesis, an open double quotation,
and one of the four loop modes: cycle, pingpong, offset, and continue,
followed by a closing double quotation.
Optionally, you can include another argument to specify the number of keyframes to evaluate
by adding a comma and a numerical value before the closing parenthesis.
Here's an interesting way to look at the four loop modes.
I have a Rocket layer with keyframes around the Planet.
If you hit "U" and open all the keyframed properties, you'll notice five keyframes
on both Position and Z Rotation.
This is actually the manual way to rotate the Rocket in a perfect circle
without using nulls, and is a great way to demonstrate the following loop functions.
The default cycle loop mode is a standard loop, repeating all keyframes from start to finish.
If you add a new expression to the Position property by "Alt (or Option) + Click" the stopwatch,
you can view the first loop mode by typing loopOut, with a capital O,
open parenthesis, double quotation, lowercase "cycle",
and then close double quotation, and close parenthesis.
So now, if you click away from the expression field, if you scrub the playhead,
you'll see the Rocket layer's Position continue looping after the last keyframe on the Position.
And if you just duplicate the expression and add a new one to the Z Rotation
and just paste it, if you RAM Preview your scene, you'll see that now both
the Rotation and the Position are looping.
But then, if you come down and, right after the double quotation, add a comma,
and then the number 2, and then copy and paste the expression to the Rotation.
This expression is basically saying use the cycle loop mode but only on the last 2 keyframes.
And if you RAM Preview your scene, you'll notice the original animation plays through,
and then the following loop only includes the last two keyframe changes.
This is a good way to loop keyframed animation while also including a nice
lead-in action that doesn't loop.
The pingpong loop mode behaves exactly how it sounds.
It plays the original keyframed animation, then reverses the animation from end to beginning,
and then plays it back again from start to finish, over and over.
In the current expression, if you change the word cycle to pingpong, all one word, lowercase,
and then copy and paste the expression to the Rotation property,
and then RAM Preview your scene, you'll see the original animation plays through,
and then it bounces back and repeats the animation, but in reverse.
If you come in and add a comma, 2, to both of these expressions,
and then RAM Preview your scene,
you'll notice all the keyframes play through, but then the last 2 keyframes bounce back and fourth.
The offset loop mode works just like the cycle mode, except it starts the next loop's value
where the previous loop's value ended.
So, if you come into your expression and change pingpong to offset, all one word, lowercase,
and then highlight the expression and paste it to Z Rotation.
And if you RAM Preview your scene, the behavior is identical to the cycle mode.
But the important difference here is the value of the last keyframe.
So, if you select the last keyframe here and change 480 to something like 360,
and click off to save your changes, you'll see the Rocket has moved slightly over.
But if you RAM Preview your scene, you'll notice the first animation plays through,
but the second animation starts where the last keyframe left off.
Continue, my favorite looping mode, allows you to continue a value using the exact
speed and direction of its last calculated frame.
It's not really a loop, per se, but it's extremely powerful.
So if you come in to offset and highlight it and change it to continue, all lowercase, one word,
and then select it, and paste it onto Z Rotation as well.
And I can illustrate this a little bit better if I just remove the last keyframes.
So now, if I RAM Preview the scene, the Rocket's gonna rotate 90 degrees around the Planet,
and then continue in a straight line.
That's pretty cool!
This is very useful for doing a quick animation, and then letting that animated object continue
off screen without actually having to set a manual keyframe for its end point.
You can find the loop expression syntax in the Expression Language Menu under the Property category
We've arrived at the end of Lesson 206: Looping a Set of Keyframes in After Effects
If you enjoy this expressions course, consider purchasing the paid content.
It includes in-depth documentation, extra tutorial content, high definition videos,
and all the project files used in the training.
Your purchase will help to create more free courses like this in the future.