Stoping using collecting string in for and while loop