5.3. The for loop

[5.2] Create and use for loops including the enhanced for loop

In this section, I’ll cover the regular or traditional for loop. The enhanced for loop is covered in the next section.

A for loop is usually used to execute a set of statements a fixed number of times. It takes the following form:

for (initialization; condition; update) {
     statements;
}

Here’s a simple example:

The output of the preceding code is as follows:

25
50
75
100
125

In the preceding example, the code at will execute five times. It’ll start ...

Get OCA Java SE 8 Programmer I Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.