Encapsulate code into a function