October 2015
Beginner
400 pages
10h 9m
English
In This Chapter
• Use the for loop
• Use the while loop
• Use the do-while loop
• Exit a loop prematurely
• Name a loop
A computer program can repeat a task with ease. Programs are ideally suited to do the same thing over and over because of loops. A loop is a statement or block that is repeated in a program. Some loops run a fixed number of times. Others run indefinitely.
There are three loop statements in Java: for, do, and while. Each can work like the others, but it’s beneficial to learn how all three operate. You often can simplify a loop section of a program by choosing the right statement.
In your programming, you find many circumstances in which a loop is useful. You can use them to keep doing ...
Read now
Unlock full access