Alternate code using “for” into code using block