## R history
``` Start with a total of 0. Add 5 to the total. Add 3 to the total. Add 9 to the total. Add 7 to the total. The total now is the answer. ``` | ``` total <- 0 total <- total + 5 total <- total + 3 total <- total + 9 total <- total + 7 total ``` |
``` Start with a total of 0. For each number x in the collection: Add x to the total. The answer is the final value of total. ``` | ``` collection <- c(5, 3, 9, 7) total <- 0 for(x in collection) { total <- total + x } total ``` |
``` This is how to add up the numbers in a collection: Start with a total of 0. For each number x in the collection: Add x to the total. The answer is the final value of total. Now add up 5, 3, 9, and 7. ``` | ``` addup <- function(collection) { total <- 0 for(x in collection) { total <- total + x } total } addup( c(3,5,9,7) ) ``` |