Lessons 6–10 · About 60 min per lesson
Decisions, loops and state
Classify one input, then apply the rule to a whole batch.
Lesson breakdown
- Lesson 6
Use if/else to classify a score and check the equality boundary.
- Lesson 7
Write score bands with else if and check their order.
- Lesson 8
Use for to process a given number of scores.
- Lesson 9
Use while to read until a -1 sentinel and exclude it from the data.
- Lesson 10
Count passes and check all-pass, all-fail and empty batches.
Worked example
Scores are 59, 60 and 75. A score of at least 60 passes.
How to solve it
The outcomes are fail, pass and pass, for a count of 2.
Assignment
Read scores until -1 and report the counts at or above 60 and below 60.
Check your result
59 60 75 -1 → 2 1; -1 → 0 0.