TOPIC 2.1 · STUDY
Algorithms with Selection and Repetition
Selection chooses which steps run after a true/false check. Repetition keeps doing steps until a condition changes. Algorithms here are described in words or diagrams, not Java syntax.
2.1.A
Selection and repetition
An algorithm can do more than list one fixed path. It can decide between paths and it can repeat work. In this topic you describe those ideas in ordinary words or in a diagram. You are naming the decision or the repeat rule, not writing Java if or while statements yet.
Selection is a true/false check that chooses which steps run next. Both outcomes must be clear. Example: if a mail slot already holds a flyer, leave it; otherwise tuck one flyer in, then stamp the envelope. Vague goals such as "handle mail nicely" are not selection, because a follower cannot tell what to test or what to do for each answer.
Repetition keeps performing steps until a stated condition changes. Example: stir paint, check whether the color matches the sample card, and stir again if it does not, continuing until it matches. A single stir with no recheck is not repetition. The stopping rule has to be something you can observe.
| Idea | What it does | What it is not |
|---|---|---|
| Selection | A true/false check chooses which steps run. | A vague wish such as "do it right." |
| Repetition | Steps repeat until a stated outcome is reached. | One fixed action with no recheck. |
| Later step | The next ordinary action after a check or loop. | Not selection or repetition just because it is last. |
The same algorithm can use both ideas. Below, a student opens a gym locker before storing a water bottle. Trying the dial again when the door stays shut is repetition. Asking whether the door opened is selection. Placing the bottle is just the next step after the door is open.
Not open loops back to another try. Open continues to place the bottle. That last action is sequencing, not another decision.
Order still matters. You cannot place the bottle before the door opens. After a selection or a loop finishes, an ordinary later step such as closing the locker is just the next instruction. Being last does not make it selection, and happening after a decision does not make it repetition.
Key points
- Selection is a checkable true/false decision with clear steps for each outcome.
- Repetition repeats steps until a stated condition changes.
- Words and diagrams are enough for this topic; Java if and while come later.
- A later ordinary step is not selection or repetition just because it comes last.
- Keep the given order: a step that needs an earlier result cannot move earlier.
A goal such as "open the locker correctly" is not an algorithm. Name the checks and the steps. Also remember: a later step is not automatically a decision or a loop just because it appears after one.