modified the counter in while loop