Objectives |
|
Suppose that you need to print a string (e.g., "Welcome to Java!" ) a hundred times. It would be tedious to have to write the following statement a hundred times:
System.out.println( "Welcome to Java!" );
Java provides a powerful control structure called a loop that controls how many times an operation or a sequence of operations is performed in succession. Using a loop statement, you simply tell the computer to print a string a hundred times without having to code the print statement a hundred times.
Loops are structures that control repeated executions of a block of statements. The concept of looping is fundamental to programming. Java provides three types of loop statements: while loops, do-while loops, and for loops.