* Use seq_along() in place of 1:length()
 * Compute the sequence seq_along(w) *once* per branch in if else
 * Spread the for() over several lines and contained it within braces