I can’t see a loop here. I can see a couple of IF statements.
What do you mean by the “run” process. Is this set to loop?
Do you mean the shift line which should just remove and return the first element of the array.
Have a look at this link which has an example of a for and forEach loop if that is what you need.