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
- Meet the Loops (modern javascript tutorial)
- Flip a coin. Rewrite using a do-while loop.
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.
Recent Comments