Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I thought something like Ctrl-C would work.

like image 635
Adrian Avatar asked Sep 09 '25 10:09

Adrian


1 Answers

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.

like image 144
Steffen Avatar answered Sep 11 '25 21:09

Steffen