Daniel M.
Daniel M.

Reputation: 1433

How to stop infinite loop in JShell / Kulla?

JShell is a Java REPL that is scheduled to be released alongside Java 9; however, there is an open beta for it.

If I create an infinite loop in JShell (Project Kulla) by typing:

-> while(true) {}

JShell will loop forever. Short of completely quitting JShell, is there a way to stop an individual line of code while it's running in JShell (after you have already begun evaluation of the code)?

Upvotes: 3

Views: 1478

Answers (1)

Maroun
Maroun

Reputation: 95968

Actually there is a way. Just hit CTRL + c:

-> while(true) {}
Killed.

-> 

It'll kill the loop and will not exit the shell.

Note that it'll take ~1-2 seconds for the kill process to finish, if you hit it twice it'll kill the statement and then will exit the shell.

I'm using JDK 9 EA build 107 on 03-01-2016 (#4560)

Upvotes: 5

Related Questions