title: How to exit loops with user input?
body: <p>How would I exit this do while loop by the user's command so the program would stop asking for more user input? I've tried to find the answer online, but none of the solutions I've tried have worked for me. This is my code below:</p>
  
  <pre><code>public double setExpenses() {
      double total = 0;
      Scanner expense = new Scanner(System.in);
  
      System.out.println("Enter Expenses: ");
  
      while (!expense.hasNextDouble()) {
          System.out.println("Invalid Data Type. Please enter a numerical value.");       //to prevent data types different from doubles
          expense.next();
      }
      finished:
      do {                                                            //supposed to continue asking for user input to add together...but how to end the loop?
          double Expense = expense.nextDouble();      
          total += Expense;                                                           //adds user input together to total
          System.out.println("Total Expenses so far: $" + total);
  
          while (!expense.hasNextDouble()) {
              if(expense.equals("done")) {                    //breaks loop if the user types "done"? idk if this is right.
                  break finished;
              }
              System.out.println("Invalid Data Type. Please enter a numerical value.");
              expense.next();
          }
  
      }while (expense.hasNextDouble());
      return total;
  }
  </code></pre>