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 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.