Real programs choose what to do and repeat work instead of running the same short list of steps every time. Here you'll run code only when a condition holds, pick between two paths and then between many, repeat a block a fixed number of times with a counting loop, and build up a running total as the loop goes round.
Overview
Syllabus
Running Code Only When a Condition Holds
- Predict, Then Run
- Print Only When Above a Limit
- Add the Other Branch
- Check Whether the Shop Can Serve
Handling Many Cases with else if
- Trace the Chain
- Sort a Value into Three Ranges
- Catch Everything Left
- Fix the Order
Repeating a Fixed Number of Times with for
- Trace a Loop
- Repeat a Message
- Number Each Pass
- Print a Price List
Building Up a Total While Repeating
- Total Up the Sales
- Show the Running Total
- Apply the Happy-Hour Rate
- Report the Day