Topic 2.1 — Algorithms with Selection and Repetition

Goal: recognize that many algorithms make decisions (selection) and repeat steps (iteration), and describe/trace simple algorithms that use these ideas.

The big idea

Many real programs follow this pattern: check a conditionchoose what to dorepeat until finished.

In Unit 2 you’ll learn Java tools for this: boolean expressions, if, loops.

Two core ideas

  • Selection: choose between paths (do A vs do B)
  • Repetition: do a step multiple times (repeat until a goal is reached)

Even “simple” algorithms become powerful when they combine both.

Selection (decision-making)

Selection happens whenever the next step depends on a condition being true or false.

// Pseudocode (not Java yet)
IF it is raining
  bring umbrella
ELSE
  wear sunglasses

In Java, you’ll write this using if statements.

Repetition (doing steps more than once)

Repetition is used when the same action needs to happen multiple times.

// Pseudocode (not Java yet)
REPEAT 5 times
  practice a problem

In Java, you’ll write repetition using while and for loops.

How selection + repetition work together (algorithm pattern)

This is a super common pattern for “keep going until done” algorithms:

// Pseudocode
WHILE not finished
  IF condition is true
    do option A
  ELSE
    do option B
Part What it means Why it matters
Condition Something you can evaluate as true/false Controls which path runs (and when loops stop)
Branch A path chosen by selection Makes the algorithm adaptable
Repeat Run the steps again Lets you solve problems with many inputs/items

Common mistakes (conceptually)

  • Forgetting to update something inside a repeat → repeat forever (infinite loop)
  • Condition is backwards → loop stops too early or never runs
  • Selection logic misses a case → wrong branch runs

Exam mindset

  • Be able to describe what an algorithm is doing in words.
  • Identify where it makes decisions (selection) and where it repeats steps (iteration).
  • When tracing, watch how the condition changes each time through the loop.

Quick self-check

  1. What is “selection” in an algorithm?
  2. What is “repetition” in an algorithm?
  3. Give one real-life example of selection.
  4. Give one real-life example of repetition.
  5. Why do many algorithms combine both?

← Back to Unit 2 topics