Changed while loops into for

Changed while loops into for