added control flow to pop an element from array
added while loop