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

  1. Lesson 6

    Use if/else to classify a score and check the equality boundary.

  2. Lesson 7

    Write score bands with else if and check their order.

  3. Lesson 8

    Use for to process a given number of scores.

  4. Lesson 9

    Use while to read until a -1 sentinel and exclude it from the data.

  5. 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.