Replaced another 'while' with a 'for'