title: Looping until user inputs "stop"
body: <p>I've been trying to code the following program and make it so that when the user inputs "stop" or "s", the program would terminate but until he inputs that word, it would keep on asking the user to input numbers to square root them. This is my code so far, in terms of functionality it is good but I just cannot seem to get this right. Thank you all.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Question5 {
      public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          double input, var = 0.0, var2 = 0.0; //initialising variables
          String x;
  
          System.out.println("Input the number to calculate square root on");
          input = sc.nextDouble(); //inputting by the user
  
  
          while(!x.equals("stop")) {
  
              x = sc.next();
              if (input &lt; 0) { //negative numbers cannot be entered
                  System.out.println("Negative numbers are not computable in this case");
                  System.exit(1);
              }
              double RepeatedInp = input;
  
              while (true) {
                  //calculation of square root of number inputted
                  var = ((RepeatedInp + input / RepeatedInp) / 2.0);
                  RepeatedInp = var;
  
                  if (var2 == var) {
                      break;
                  }
  
  
                  var2 = var;
              }
              System.out.println(var); //printing
  
  
          }
  
  
      }
  }
  </code></pre>