for Loops

In the Java programs that you write, you will find many circumstances in which a loop is useful. You can use them to keep doing something several times, such as an antivirus program that opens each new email you receive to look for any viruses. You also can use them to cause the computer to do nothing for a brief period, such as an animated clock that displays the current time once per minute.

To create and control loops, you use a loop statement. A loop statement causes a computer program to return to the same place more than once. If the term seems unusual to you, think of what a stunt plane does when it loops: It completes a circle and returns to the place where it started the loop.

The most complex of the loop statements is for ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.