for Loops

In your programming, you 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 received to look for viruses. You also can use loops to cause the computer to do nothing for a brief period, such as an animated clock that displays the current time once per minute.

A loop statement causes a computer program to return to the same place more than once, like a stunt plane completing an acrobatic loop.

Java’s most complex loop statement is for. A for loop repeats a section of a program a fixed number of times. The following is an example:

for (int dex = 0; dex < 1000; dex++) {    if (dex % 12 == 0) {        System.out.println("#: " + ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth 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.