Indefinite Loop Example in Java
Indefinite Loop Example in Java
Let’s look at indefinite loop example in Java.
What is Indefinite Loop?
An indefinite loop is a type of loop in programming that continues to execute as long as its condition remains true. The exact number of iterations is not known before the loop starts,
making it indefinite. The loop terminates only when the condition evaluates to false.
Indefinite Loop Example
public class IndefiniteLoopExample { public static void main(String[] args) { // Indefinite While Loop Example // - www.TestingDocs.com int loopNumber; loopNumber = 0; while (true) { loopNumber = loopNumber + 1; System.out.println("This Loop runs forever! ... " + loopNumber); } } }
Indefinite loops are useful in scenarios where the number of iterations depends on external factors or dynamic conditions, such as waiting for user input, monitoring a sensor, or continuously processing requests in a server.