replace 'while's with 'for's