Can you loop a part of an animation?

Is there a way through scripting that you could loop a part of an animation instead of the whole thing? Like looping just the last second or so of an animation? Or is that impossible?

Not that I’m aware.