You can use System.exit(0)
provided you fork a new console / REPL. If you run via SBT, then fork in console := true
will accomplish that. If you're launching a REPL from within your code and using run
in instead of console
, then you'd want fork in run
.
If you want to run a stand-alone REPL, then start your program and eventually have it exit back to the REPL, then you'll need to simply stop your read loop and return out of the entry-point method you called to start it up.
Given how little code you included, it's hard to say much more than this.