replace the for() with the while() loop because its easier to introduce