Can I stop the execution of an infinite loop in Scala 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){}
开发者_Go百科
I thought something like Ctrl-C would work.
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.
精彩评论