changed loop in step 3 from while to for