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

Ok, thanks guys, will re-read your comments right after this and try to better the code.

Im trying to post the complete code here but I cant, it exceeds 9000 characters.
Anyway around this?