Infinite For loop

  1. /*

  2.   Infinite For loop Example

  3.   This Java Example shows how to create a for loop that runs infinite times

  4.   in Java program. It happens when the loop condition is always evaluated as true.

  5. */

  6.  

  7. public class InfiniteForLoop {

  8.  

  9. public static void main(String[] args) {

  10.  

  11. /*

  12.   * Its perfectely legal to skip any of the 3 parts of the for loop.

  13.   * Below given for loop will run infinite times.

  14.   */

  15. for(;;)

  16. System.out.println("Hello");

  17.  

  18. /*

  19.   * To terminate this program press ctrl + c in the console.

  20.   */

  21. }

  22. }

  23.  

  24. /*

  25. Output would be

  26. Hello

  27. Hello

  28. Hello

  29. Hello

  30. ..

  31. ..

  32. */

0 comments: