In a game I'm building, the user is given some options from which they can choose by pressing a number. A switch statement then runs the relevant method. One of the options is to exit the game, which I do by running System.exit(0)
. I was wondering, if the break after the exit is still useful, and if so, why? And is there a difference if the exit
is the last option in the switch statement, or not?
Code goes as follows:
switch(choice) {
case 1: getEntityOverview();
break;
case 2: worldMap.PrintMap();
break;
case 3: moveAllOnInput();
break;
case 4:
System.out.println("You are exiting the game, "
+ "thanks for playing!");
System.exit(0);
break;
}