writing code outside of the loop

I remember seeing an example code somewhere, where a chunk of code was written outside of the loop and called from inside the loop with an if statement. now I am unable to find that example to see the syntax. I am working on a project where writing subroutines outside of the loop would be much easier. can someone tell me the proper syntax?

thank you that is exactly what I needed .