The Infinte For Loop – Java

The infinite for loop is rather similar to the standard infinite while loop. The while loop uses true as an argument and will continue to operate forever because the argument is true and will not change. Similarly the infinite for loop works almost the exact same way. It uses true as it’s boolean expression and just leaves the initialization as null and the stepper as null. It looks like this.

1
2
3
4
5
6
7
8
9
10
//creating an infinite loop by making the boolean value true and the other expressions null.
for(; true ;){
    System.out.println("Test");
}
 
//similar to this there is the while loop.
while(true){
    //The expression just needs to be true.
    //for example, it could be while(5 > 2){...
}

Related posts:

  1. The Comma Operator in Java
  2. Java: basic for and while loops
  3. Java: Pass as many strings as you want through a method
  4. Reading information from a binary file with java
  5. Creating user input with menus in java
Caleb Jonasson

About: Caleb Jonasson

I am a web application developer currently spending my days coding at work, completing contracts and running around with my Nikon. This is my primary place for updates and everything code, technology and database related.
  • http://www.google.com/ Maribeth

    I feel so much happier now I understand all this. Thnaks!

  • tsm

    What’s the matter with “for(;;)”?