Added functionality for a while loop.