For Statement

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]

*Syntax:
for ( InitStatement ; Expression1 ; Expression2 ) Statement
 
*InitStatement, Expression1, and Expression2 are optional.
 
*Semantics: The for loop comes close to following while construct:

{
   InitStatement;
   while ( Expression1 ) {
      Statement
      Expression2;
   }
}

 

*Layout according to our coding standard:

for ( InitStatement; Expression1; Expression2 ) {
    Statement1
    Statement2
    ...
}

 

Factorial.java
      // compute n!
      factorial = 1;
      for (int i = 1; i <= n; ++i) {
         factorial *= i;
      }

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]  [Next Chapter]
Copyright © 2001, 2002 Andreas Borchert, converted to HTML on February 11, 2002