Task 7 Practical Guide

Selection And Iteration

Build the decision and repetition logic that practical tasks commonly require.

Steps

  1. 1 Build the sequence for one item first.
  2. 2 Add the selection condition and test it with one value.
  3. 3 Check boundary operators such as `<`, `<=`, `>` and `>=`.
  4. 4 Add the loop after one cycle works.
  5. 5 Check whether the final output should be inside or outside the loop.

Examples

Selection

`IF totalMinutes >= 30 AND totalMinutes <= 60 THEN balancedCount <- balancedCount + 1`

Fixed loop

`FOR session <- 1 TO 3` suits exactly three sessions.

Validation loop

`WHILE rating < 1 OR rating > 5` suits repeated input until valid.

Avoid

Copying repeated code instead of looping

Updating counters outside the condition

Using `=` when a language requires comparison syntax

Task 7 Syllabus Reminder

Integer, real, Boolean and character data types.
Meaningful variable naming conventions.
Source code and executable code.
Sequence, one-way selection, two-way selection, multi-way selection, test-first iteration, test-last iteration and fixed iteration.
Syntax, run-time and logical errors.
Data validation, test data and trace tables.
Flow charts and pseudocode used to model and test algorithm logic.
Internal and external documentation where relevant.