Refactor for loop to use cond