There are a couple types of loops in programming such as for loops, while loops, and do-while loops (I don’t know if you can do these in AE). They don’t cover this kind of stuff in the help docs, I learned it from a programming class (AP Computer Science AB) that I’m taking right now in Java. I would reccomend buying a book o Javascript and skipping over all the web related stuff and learning syntax of things like loops, variables, functions etc. I think on motionscript.com Dan reccomends a few books.
~Colin