R 嵌套循环
嵌套循环
也可以将一个循环放在另一个循环内。这称为**嵌套循环**。
示例
打印列表中每个水果的形容词
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}
亲自尝试 »
也可以将一个循环放在另一个循环内。这称为**嵌套循环**。
打印列表中每个水果的形容词
adj <- list("red", "big", "tasty")
fruits <- list("apple", "banana", "cherry")
for (x in adj) {
for (y in fruits) {
print(paste(x, y))
}
}
亲自尝试 »
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]