Introduction: 4.4.0

  • A nested loop has one loop inside of another
    • Used for working with two dimensions
      • rows and columns
  • When a loop is nested, it runs many times inside an outer loop
    • Every time the outer loop iterates, the inner loop runs
// make a triangle!

for (int depth = 1; depth <= 5; depth++) {
    for (int i = 0; i < depth; i++) {
        System.out.print("*");
    }
    System.out.println();  // Print a new line!
}
// output
//
// *
// **
// ***
// ****
// *****

Summary: 4.4.3

  • Nested iteration statements are iteration statements that appear in the body of another iteration statement
  • The inner loop must complete all it’s iterations before the outer loop iterates again