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:
- Sequence
- Selection
- Iteration (a.k.a., Loops)
Examples
- JavaScript has three loop statements: while, for, do-while.
- JavaScript Loops (dofactory.com)
- Use a while loop to flip a coin. Exercise: rewrite using a do-while loop.
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.