modernize while-loop to for-loop