How to get code-snippet to only 'loop' once?

Ok..
How could I "translate" this to a function?
And call it from the loop?