小编Adr*_*sey的帖子

即使是最简单的 for 循环也无法在 RStudio 中工作

我的程序中以前工作的 for 循环都没有按预期运行。我想知道我是否对 RStudio 环境/配置做了一些操作来打破 for 循环?...或者也许,我在这里缺少一些非常基本的东西?

考虑一个基本的 for 循环示例,例如

for (year in 2010:2015){
print(paste("The year is", year))}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,即使这个循环也没有向我的控制台返回任何内容。现在,考虑一个基本的 while 循环,比如说

count <- 0
while (count <10) {
  print(count)
  count = count +1}
Run Code Online (Sandbox Code Playgroud)

这个 while 循环返回预期的

[1] 0
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
Run Code Online (Sandbox Code Playgroud)

loops for-loop r while-loop

0
推荐指数
1
解决办法
1818
查看次数

标签 统计

for-loop ×1

loops ×1

r ×1

while-loop ×1