while loop to process till the end