Service Model: How can I create an iterative loop with the elements in the palette?

Service Model: How can I create an iterative loop with the elements in the palette?

I want to create a for (var i=0;...) but I want to implement the body of the loop in separate script to support it more easier.
Is this possible?