Added break option to the loop function