title: While loop with .hasNext condition running infinitely
body: <p>I know this has been asked many times on StackOverflow, but i've tried many different solutions, and none of them have worked. So i've decided to ask the community on what to do. Here is the relevant snippet from my code.</p>
  
  <pre><code>public class Calculator
  {
    public static void main(String[]args)
    {
       ArrayList&lt;String&gt; inputStorage = new ArrayList&lt;String&gt;();
       Scanner input = new Scanner(System.in);
       String rawInput;
       boolean mainLoop = true;
  
       String exitInput;
       String mainMenuInput;
  
       while(mainLoop == true)
       {
          mainMenuInput = input.nextLine()
          switch(mainMenuInput)
          {
             case "Expression":
                 System.out.println("Type an expression");
                 while(input.hasNext)
                 {
                    rawInput = input.next();
                    inputStorage.add(rawInput);
                 }
                 break;
  
             case "Equation":
                 System.out.println("Type an equation");
                 while(input.hasNext)
                 {
                    rawInput = input.next();
                    inputStorage.add(rawInput);
                 }
                 break;
            case "exit":
                System.out.println("Are you sure you want to exit")
                exitInput = input.nextLine();
                switch(exitInput)
                {
                   case "yes":
                   case "Yes":
                   mainLoop = false;
  
                   case "no":
                   case "No":
                   break;
  
                   default:
                   System.out.println("That was not an option")
                   break;
                }
            default:
                   System.out.println("That was not an option");
                   break;
  
          }
       }
  </code></pre>
  
  <p>Keep note, this is just the part of my code that takes in input from the console with nothing else included. I have other things setup that require the code to be in this format.</p>
  
  <p>Here is a list of what i've tried and hasn't worked:</p>
  
  <ul>
  <li>replace input.hasNext() with input.hasNextLine()</li>
  <li>replace input.hasNext() with input.next() != null</li>
  <li>making exit condition if input.next = null</li>
  <li>making exit condition if input.next() = "\n"</li>
  <li>making exit condition if input.next() = "\r"</li>
  </ul>
  
  <p>Here is a list of things that won't work for the rest of my code:</p>
  
  <ul>
  <li>BufferedReader (and all methods and aspects of it)</li>
  <li>replace input.next() with input.nextLine()</li>
  </ul>
  
  <p>With that said, i have seen a way of doing this by making an exit condition based on the ASKII value of the character newLine. The only problem is that I have found no good way of implementing ASKII values of characters into java code (or at least none that would work with my code), and in order to implement it, I would need to know how the Scanner class uses the Next Line character. But this is just one proposed solution, and i'm sure someone has a better way of ending an input loop like this when enter is pressed.</p>
  
  <p>Thank you for your time.</p>