Replace break with while condition