如何将输入用作用户输入
我有一个循环,我希望它仅在您击中控制台时进入下一个“ i” - 值。所以我写了这篇文章:
for (i in 1:5){
print(i)
UserInput <- readline(prompt = "Press enter to continue.")
if (UserInput != "ENTER"){ #Obviously "ENTER" is incorrect, but something like that.
break
}
}
有线索吗?
I have a for loop and I want it to only go to the next "i"-value when you hit enter in the console. So I wrote this:
for (i in 1:5){
print(i)
UserInput <- readline(prompt = "Press enter to continue.")
if (UserInput != "ENTER"){ #Obviously "ENTER" is incorrect, but something like that.
break
}
}
Any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个简单的解决方案是:
A simple solution is:
这种方法将促使用户按Enter按ENTER,并在此操作时转到下一个
i
:如果您希望第一个结果(1)仅在“ Enter”之后显示,则只需交换这两行,
打印
和readline
。编辑:根据评论,如果输入“ Enter”以外的其他内容,您可以中断
This approach will prompt the user to press enter, and will go to the next
i
when they do so:If you want the first result (1) to show only after an "enter", then just swap the two lines,
print
andreadline
.Edit: based on comment, you can break if something other than an "enter" was input