Skip to content
Advertisement

how do I break a while loop when asking for user input?

i need to try to break the while loop when a user enters an empty line instead of countries. Here is the code I have done so far and it does not seem to want to end the loop of asking for countries:

JavaScript

the user input should look as follows:

JavaScript

Advertisement

Answer

Your checking for hasNext() but should be checking for hasNextLine().

However, don’t do either:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement