O'Reilly logo

Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) by Marcus Green, Bill Brogden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The for Loop Structure

Java provides the for loop to let you repeat blocks of code under control of a loop counter variable. The general form of the for loop is a for statement followed by a loop body. The for statement consists of three sections, as shown in the following code:

for( initialization ; logical test ; update )

When a for statement is executed, the first thing that happens is that the initialization expressions, if any, are executed. Next, the logical test expression, if present, is executed—if the result is false, the loop is exited immediately. If there is no logical test or the result is true, the loop body statements are executed. Finally, the update expressions, if present, are executed and the logical test is repeated.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required