Array
University of Oregon

Loops (for Iteration)

Terminology

  • Flow of Control =  which statement gets executed next? A.k.a., logic flow.
  • Control Structures = statements which control logic flow
  • Three categories of control structures:
    1. Sequence
    2. Selection
    3. Iteration (a.k.a., Loops)

Examples

Optional Case Study

The peasant multiplication algorithm (PMA) is an ancient system for multiplying two numbers. It requires only the ability to double, divide by 2, and add.

Exercise: Translate the pseudocode PMA into a JavaScript function named PMA that accepts two numbers and returns their product.

Skip to toolbar