Make structural changes to make it easier for you.
We are going to change it so that the do-while loop always works until you explicitly stop it.
Current time:
while(stdIn.nextLine().compareToIgnoreCase("q")==0);
Which works fine, but we have an easier way to do this. Have you heard of the break statement?
I suggest you use break . This statement will break you out of the while loop; it basically tells the program to end the loop when it is called. It will be a little easier to follow than your somewhat confusing business.
do { //Your Do code goes here, as before ... // //Your newly added break statement will go here. //This breaks out of the while loop when your inputed 'choice' value is //equal to the string of "q" (for quit) if (Choice.equals("q"))){ break; //When break is called nothing else in the loop will run } //Same thing but with the string of "quit" if (Choice.equals("quit"){ break; } }while (true); //Your new while statement is simply while(true) which will run until break is called
Hope this is helpful for you.
Panky source share