Extended ex13 with a while loop