Streamlined the code

Implemented a for loop while trying to learn the use of methods.