Looping like this was discussed a bit in this post: How to change the geometry in each loop? which should provide a good starting point.
As you want to modify the geometry between runs, the first thing to do is ensure your program supports changing the geometry between runs. See @mkelsey’s comments on the appropriate UI commands in that post on how to do this.