Tutorials References Exercises Bootcamp Menu
Sign Up Create Website Get Certified Upgrade

R Nested Loops

Nested Loops

It is also possible to place a loop inside another loop. This is called a nested loop:


Print the adjective of each fruit in a list:

adj <- list("red", "big", "tasty")

fruits <- list("apple", "banana", "cherry")
  for (x in adj) {
    for (y in fruits) {
      print(paste(x, y))
Try it Yourself »