Tsallaka zuwa abun ciki
Justice Tech School

for and while Loops

for walks a vector and while repeats on a condition. break and next control loops.

Example
for (i in 1:5) {
  if (i == 2) next
  if (i == 5) break
  cat(i, "")
}
cat("\n")
n <- 3
while (n > 0) { cat(n, ""); n <- n - 1 }
cat("\n")

Exercise

Skip a round.

Quiz Test

What does next do?

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