Can I stop the execution of an infinite loop in Scala REPL?

别说谁变了你拦得住时间么 提交于 2019-12-22 01:52:21

问题


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){}

I thought something like Ctrl-C would work.


回答1:


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.

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.

The change was introduced with Scala 2.9.0.RC2. See the changelog (part: Repl Improvements) for further details.

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

on a windows system to view the whole comment for this binding. I guess this is a bug on windows.



来源:https://stackoverflow.com/questions/6248884/can-i-stop-the-execution-of-an-infinite-loop-in-scala-repl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!