You can:
Most components can be handled like this.
looping inside a function
You can run loops inside functions but you probably have something else / specific on your mind - something latent - not a function territory.