Teach nested loops using ASCII art, building from triangles to diamonds through iteration.

  • This exercise takes 2-3 in a high school AP classroom.
  • In addition to building comfort with nested loops, students necessarily become familiar with managing and keeping track of multiple counters.
  • On day one have students build an equilateral triangle using strings and characters.
    • The first row will have 1 star, indented.
    • These instructions and exercise are good because it is easy for students to picture what they’re supposed to create.
    • On the first iteration of day one, student’s often end up with a triangle that looks as follows because they don’t put enough spaces in front of the stars.
  • On day two have students extend the shape to build a diamond.
  • Finally, on day three require students to create one large loop that constructs the diamond from beginning to end.

More about this tip

External Source

Interview with Joon Kim

Other Tips By