Iteration Statements

Java provides three different types of iteration statements: for, while, and do. It also provides the continue statement to alter execution of for, while, and do. These statements, taken from C and C++, are used to repeat the execution of a statement or block of statements until a termination condition occurs.

The for Statement

The for statement repeatedly executes a statement or statement block and updates a variable (or group of variables) with each loop iteration. The syntax of the for statement is as follows:

for(initialization; boolean expression; iteration)
 statement block

A single statement can be used instead of the statement block. The execution of the for statement is executed as follows:

  1. The initialization statement(s) ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams 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.