Changed while to do-while loop.