Skip to content
Justice Tech School

R For and While Loops

for iterates over a vector, while repeats on a condition and repeat loops until break. next skips a round.

Example
for (i in 1:3) print(i)
n <- 3
while (n > 0) { n <- n - 1 }
for (f in c("a", "b")) cat(f, "")
cat("\n")

Exercise

Loop over 1 to 3.

for (i  1:3)

Quiz Test

What does next do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.