What does for (;;) {} mean in java

2

for example what does the for (;;) {} do here? which means the ;; inside the for?

    double parseExpression() {
        double x = parseTerm();
        for (;;) {
            if      (eat('+')) x += parseTerm(); // addition
            else if (eat('-')) x -= parseTerm(); // subtraction
            else return x;

        }

    }
    
asked by jony alton 20.11.2018 в 05:47
source

1 answer

3

The use of ;; in the declaration of your loop, makes it infinite; look at the next couple of examples

INFINITE LOVERS

Through the following example, you can observe that it is to declare an infinite loop; you are not declaring neither the variable that is going to be used nor the counter, much less the limit to be respected.

public class MyClass {
    public static void main(String args[]) {
      for(;;)
      {
          System.out.println("Hola");
      }
    }
}

You can also see it in the following way, you declare the variable to use and an initial value and then the increase counter and the same will be infinite

public class MyClass {
    public static void main(String args[]) {
      for(int numero = 0;;numero++)
      {
          System.out.println(numero);
      }
    }
}
    
answered by 20.11.2018 в 05:58