Convert 'for' statements to range base loops to improve readability