Repeating code is awful. A function would allow you to write code, then pass a pin to that code and have it act on the passed pin reference.

Try hooking up 12 switches and 12 relays and not have any repeating code!