Prev Next

Java / Control Statements

How is an infinite loop declared in Java?

Infinite loops are those loops that run infinitely without any breaking conditions.

  • Using for Loop:
    for (;;)
    {
       // Business logic
       // Any break logic
    }
    

  • Using while loop:
    while(true){
       ...
       // Any break logic
    }
    

  • Using do-while loop:
    do{
       ...
       // Any break logic
    }while(true);
    

More Related questions...

Show more question and Answers...


Comments & Discussions