For loop into a function

I use that as the simulation program