Added for loop to the code along with comments.