Array
University of Oregon

Meet the Loops

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 Loop Practice

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 Peasant Multiplication Algorithm (PMA) into a JavaScript function named PMA that accepts two numbers and returns their product.

Skip to toolbar