Iteration (Loops)

Objective

Students must use loops to process collections of data and repeat operations.

Evidence

Using loops for game objects:

  • Ghost.js - Distance calculation loop for pathfinding
  • GameLevelOutside.js - Array.from() and map() for processing collections
  • Multiple levels - Iterating over game objects in updates and renders

Implementation Details

  • for loops for traditional iteration
  • forEach() for functional iteration over arrays
  • map() for transforming array elements
  • Loops iterate over game object collections
  • Animation frames updated in loops

Key Concepts

  • Loop types: for, while, forEach, map
  • Array iteration patterns
  • Loop control (break, continue)
  • Nested loops for complex operations