An infinite loop in Java is a loop that never stops executing because its termination condition is always true or never reached. These loops are common in servers, games, and background processes.
break or external stop to exitJava supports infinite loops using while, for, and do-while constructs. The most common form uses while(true).
// Infinite loop using while(true)
while(true){
System.out.println("Running forever...");
}
// Infinite loop using for statement
for(;;){
System.out.println("This loop has no end condition");
}
The program continuously prints messages to the console. It will only stop if the program is manually terminated or a break statement is introduced.
breakbreakfor loop to intentionally make it infinite