title: How to exit a loop based on what user pressed?
body: <p>I am making a simple average grade calculator. Basically takes in users mark and the percentage of that module and displays the average percentage. The program does work but it has a few glitches which happens in the while loop.
  The while loop should end as soon as the user enters any value under -1 but it continues on for a few times and then exits the while loop. Also, it first lets the user enter a number to ensure to start the while loop and then the text 'Enter Mark' comes up which makes the user enter their marks again. Im trying to make the while loop automatically start but dont know how too.</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  public class percentage {
  
      static ArrayList&lt;Double&gt; marks = new ArrayList&lt;&gt;();
      static ArrayList&lt;Double&gt; percentage = new ArrayList&lt;&gt;();
      static Scanner input = new Scanner(System.in);
  
      static void addingToMarks(double currentmark) {
          marks.add(currentmark);
      }
  
      public static void main(String[] args) {
  
          System.out
                  .println("Type in the number of marks you got \n"
                          + "in the module. And then type the percentage weight of it.\n"
                          );
  
          double exitLoop = input.nextDouble();
  
          while (exitLoop &gt; -1) {
  
              System.out.println("Type in your marks");
              marks.add(input.nextDouble());
  
              System.out
                      .println("Type in the weighted percentage of the module: ");
              percentage.add(input.nextDouble());
  
              exitLoop = input.nextDouble();
  
          }
  
          System.out.println(percentage);
          System.out.println(marks);
  
          System.out.println("Your average percent for the module is: "
                  + gradeCalculate());
      }
  
      static double gradeCalculate() {
  
          double totalaverageweight = 0;
  
          for (int x = 0; x &lt; marks.size(); x++) {
              totalaverageweight += ((marks.get(x) / 100) * percentage.get(x));
          }
          return totalaverageweight;
      }
  
  }
  </code></pre>