Added while loops for repeated operations.