next up previous
Next: Observations on the for Up: Unit 06 Previous: Loop controlled by a

The for loop


for statement

Syntax:

for (initialization; condition; update)
  statement

Semantics: is equivalent to

{
  initialization;
  while (condition) {
    statement
    update;
  }
}

(There is an exception in the case of the continue statement, which needs to be translated in a more complicated way.)

Example: Print out 100 stars.

for (int i = 0; i < 100; i++)
  System.out.print("*");


next up previous
Next: Observations on the for Up: Unit 06 Previous: Loop controlled by a