corrected while loops

corrected while loops