If you are using the same code more than once, it is better to write the relevant code as a method and then call it everytime. Makes it easy to maintain.