total <- 0 # for iterates over the elements of a vector for (i in 1:5) { total <- total + i } print(total)
iterate over a vector