Adding more items to the list makes the loop go around more times:
my_words <- c("Hello", "R", "Goodbye", "R")
for (word in my_words){
print(word)
}
Rscript loop.R
[1] "Hello"
[1] "R"
[1] "Goodbye"
[1] "R"
A list with a mixture of data types can be printed witout issue:
my_words <- c("Hello", "R", 404, "Goodbye", "R", 42)
for (word in my_words){
print(word)
}
Rscript loop.R
[1] "Hello"
[1] "R"
[1] "404"
[1] "Goodbye"
[1] "R"
[1] "42"
Looping over an empty list does not print anything:
my_words <- c()
for (word in my_words){
print(word)
}
Rscript loop.R