Reputation: 233
So I made this scala file and it works great when I load it into the REPL. What I want to do though is when the user inputs "Q", it exits the program and returns to the REPL. I already have readLine set up with a case match that says:
case "Q" =>
I just don't know what to put after it to make the program quit.
Thanks
Upvotes: 4
Views: 21081
Reputation: 26486
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.
Upvotes: 15