replace for comprehesion with while