我可以停止在 Scala REPL 中执行无限循环吗? [英] Can I stop the execution of an infinite loop in Scala REPL?
问题描述
我可以停止在 Scala REPL 中执行无限循环吗?键入此内容并尝试在不退出 REPL 的情况下停止它.
Can I stop the execution of an infinite loop in Scala REPL? Type this and try to stop it without quitting the REPL.
while(true){}
我认为像 Ctrl-C 这样的东西会起作用.
I thought something like Ctrl-C would work.
推荐答案
这取决于您的 Scala 版本.如果您已经在使用 Scala 2.9,只需使用 CTRL-C 即可.命令到达 REPL 可能需要一些时间,但它会在某个时候中止您的无限循环.
It depends on your scala version. If you are already on scala 2.9 it will work by just using CTRL-C. It might take some time untile the command reaches the REPL but it will abort your infinite loop at some time.
如果您使用的是旧版本的 scala(2.9 之前).没有办法停止执行.在这些版本上,CTRL-C 将导致整个 Scala REPL 终止.
If you are on an older version of scala (before 2.9). There is no way to stop execution. On those versions CTRL-C will lead to termination of the whole scala REPL.
此更改是在 Scala 2.9.0.RC2 中引入的.有关详细信息,请参阅变更日志(部分:Repl 改进).
The change was introduced with Scala 2.9.0.RC2. See the changelog (part: Repl Improvements) for further details.
这在 Windows 上不起作用,因为 Scala Windows 发行版的 Scala REPL 键绑定用切换改写模式"覆盖了 CTRL-C.输入
This doesn't work on windows, since the Scala REPL keybindings of the scala windows distribution override CTRL-C with "toggle overtype mode". Type
scala> :keybindings
在 Windows 系统上查看此绑定的完整注释.我猜这是 Windows 上的一个错误.
on a windows system to view the whole comment for this binding. I guess this is a bug on windows.
这篇关于我可以停止在 Scala REPL 中执行无限循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!