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.