首页 文章

R for循环跳转到下一次迭代ifelse

提问于
浏览
69

假设你有一个像这样的for循环

for(n in 1:5) {
  #if(n=3) # skip 3rd iteration and go to next iteration
  cat(n)
}

如果满足某个条件,如何跳到下一次迭代?

1 回答

  • 120
    for(n in 1:5) {
      if(n==3) next # skip 3rd iteration and go to next iteration
      cat(n)
    }
    

相关问题