The syntax and order of execution of Java for loop

  About java for loop surely we are very familiar with, it is one of the commonly used java statement. The for loop is the most flexible and the most common looping constructs, expression is generally as follows:
for (Expression 1; 2 Expression; Expression 4 ) { 
    Expression 3; 
}

 

  
The order of execution:

      1) the first cycle, that cycle initialization parameters

      First, the expression 1, and is generally defined as a loop variable is initialized;
      Then, the expression 2 (typically conditional statement), the expression 1 determines whether the loop variable defined in the conditional expression 2, and if so, Expression 3 is performed. Otherwise, the loop is terminated;
      Finally, the expression is executed 4, updates the loop variable.
      2) cycle again
     First, determine whether the expression 2 is true; if true, continue with expression 3; otherwise, out of the loop body; the last execution Expression 4, variable update cycle again. And so forth, until 2 expression is false.
 
     Summary: consistent order of execution, to carry out determination condition (expression 2), and then performs the function body (Expression 3), the last expression is executed 4. And so forth, except that the object of the judgment condition, in the first judgment, the expression 1 is executed, initializes the object, the object is the result of the subsequent determination (Expression 4) is performed.
 

Guess you like

Origin www.cnblogs.com/east7/p/11665148.html