Chapter 11 for loops

A for() loop works in the following way:

for(i in sequence) {
expression
}

The letter i can be replaced with any variable name, sequence can be elements or the position of these elements, and expression can be anything. Try the examples below:

for (a in c("Hello", "R", "Programmers")) {
    print(a)
}
for (z in 1:4) {
    a <- rnorm(n = 1, mean = 5 * z, sd = 2)
    print(a)
}
## [1] "Hello"
## [1] "R"
## [1] "Programmers"


## [1] 6.110161
## [1] 8.162759
## [1] 14.48589
## [1] 19.3271