Holy switch statement Batman O.O. Do you HAVE to use that? You really, really, really should use if statements there
if (score >= 90) {
} else if (score >= 80) {
}
etc. It’s cleaner, it’s more self explanatory, it’s harder to make a mistake, and it’s likely more efficient. Imagine if you missed one number in that whole mess of cases and you were desperately trying to debug why the input “62” isn’t working right, it’d be hell to find in a larger program.
Also, do… while loops are evil. Now, in programming “evil” doesn’t mean “never use it” (except for goto, unless you’re deliberately obscuring code never use goto), it means “there better be a damn good reason.” In this case, there isn’t, your problem could easily be solved by pre-declaring exit:
boolean exit = false;
while (!exit) {
[... stuff]
else if (response.equalsIgnoreCase("q"){
exit = true;
} else {
System.out.println("Enter more data?" /* blah blah blah */);
exit = response.equalsIgnoreCase("e");
}
}
System.out.println("goodbye");
The principal behind a do while loop is “do this at least once.” You can ALWAYS restructure a do…while loop as a while loop, however, there are (rare) cases where it’s cleaner because otherwise you have to type
/* do stuff /
while (something){
/ do the same stuff */
}
which is cleaned up by:
do {
/* do stuff */
} while (something);
But the cases where this happens is rare, usually what you want to do for such simple conditional while loops is initialize what’s known as a “flag” (like exit) to whatever value will let it “fall through” the while conditional the first time. In most cases, a simple flag is all that’s needed.
Edit: The one case where I’d really use a do…while loop is to clean up a statement where you want a function to meet some parameter only once.
do {
println(counter);
while (counter.increment < 5)
This will print out a counter > 5 exactly once. This specific example isn’t too helpful, but it illustrates a case where you MAY want to use a do…while loop. Honestly, I almost never see them in practice.