After Effects Tips: Loop With Expression
You mographers probably use a simple loop expression, “loopOut()”. And I think once you’ve thought that you wanted to loop only specific keyframes like an image above. It’s easy to do with expression!


loopOut("cycle", 2);


[Quick Explanation]

loopOut(type="cycle", numKeyframes=0);

loopOut() has 2 arguments, loop type and number of keyframes. The number of keyframes is keyframe segments to loop. If you use “loopOut(“cycle”, 1)”, it loops the segment bounded by the last keyframe and second to last keyframe. See my quick expression sample GIF below. Of course, you can choose your loop type from cycle, pingpong, offset and continue.
Anyway, I recommend you to read the Adobe Help page about loopOut() expression once.

After Effects Tips: Loop With Expression Sample

I would much appreciate it if you could give me a feedback. So please don’t hesitate to get in touch with me if you find some errors or better ways.
I hope this tips help you out even just a bit.

18 thoughts on “ After Effects Tips: Loop With Expression ”

  1. after year now i finally understand what I do when using loopOut. now I wonder how to say at the expression that I want to loop between specific keyframes ( lets say, between the second and 4th keyframe in your example), without need to use sliders, duplicate comp layers and these sorts of things. Thanks!

    1. Thank you for your comment. I’m glad if it’s helpful for you.
      I’m sorry but I’m not sure your goal. But “if/else” conditional might be useful for some cases.

  2. Very good explanation, thanks! I gotta a question.. What if I want to make an animation loop until it reaches a certain point in time? Is that easy to achieve?

    1. Thank you for your comment, Gustavo.
      It depends on the situation/condition but how about this expression?

      t = 10; // set your time to stop loop
      if(time < t){
      } else {
      value; // or something you want

      1. Thanks a lot Beatgram, this is a cool code snippet. Sheer genius!!

      2. Thank you!! That’s just incredible. It’s my first day of learning After Effects and I already feel like a programmer :))

  3. Oh dude, this is the clearest explanation of the loopOut/loopIn I’ve seen, especially the “play once, loop forever” part. If they are not linking to this from the official Adobe AE online help, they should be. Thanks so much for taking the time to write this up 🙂

    1. Thank you so much for your sweet words, Lori! I’m glad you like it.
      I think this is just the power of animation/motion graphics to communicate.

  4. I wonder is there any way to make a loop that plays before AND after keyframes. That would help my animation a lot.
    I’ve just realised expression “loopIn() + loopOut() – transform.position” can do the work, but is there a more elegant way?

    1. I’m not sure if it’s helpful for you but here’s a typical sample.

      if(time < key(1).time){
      } else {

      1. Thank you! I thought there is some kind of loopInOut() type of command, but now I have at least two working variants.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s