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 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!