Introduction to Java using NetBeans

Section 6 : Loops

 

Infinite Loop

The condition of a loop is used to determine when the loop should stop executing.

A loop continues until its condition is false.  What happens though, if the condition never becomes false? The result is an infinite loop—one which continues on forever!

Infinite loops cause the application to stop responding or “hang.” If this happens you can end the execution of your program by pressing the stop button on the left side of the output window.

Example Icon Example 6

// BAD CODE- creates an infinite loop
// USE AT OWN RISK!

for (int i = 0; i < 10; i--){
     System.out.println(i);
}