ACSA Exam Prep
Unit 2 · Selection and Iteration · Topic 2.1

Algorithms with Selection and Repetition

Skill 1.A

Big idea: Every algorithm is built from three blocks: do steps in order (sequencing), choose between paths (selection), and repeat (repetition).

Learning objectives
  • Represent patterns and algorithms that involve selection and repetition found in everyday life using written language or diagrams.

The three building blocks

BlockEveryday exampleJava
SequencingPut on socks, then shoesStatements one after another
SelectionIf it's raining, take an umbrellaif, if-else
RepetitionStir until the sugar dissolveswhile, for

Order changes the outcome

The same steps in a different order can give a different result. Here, checking before or after adding changes what is printed.

Code
int total = 0;
for (int i = 1; i <= 4; i++) {
  total += i;
  if (total > 5) {
    System.out.println("over at i = " + i);
  }
}
Output
over at i = 3
over at i = 4
Key points
  • The building blocks are sequencing, selection, and repetition.
  • Selection picks a path based on a true/false decision.
  • Repetition repeats a process until a goal is reached.
  • The order in which blocks are combined affects the outcome.
Watch out
  • Swapping two steps can change the result even when the steps themselves are the same.
Quick check
"Keep asking for a password until it is correct, then say welcome." Which blocks does this use?
Show answer
Repetition (keep asking), selection (is it correct?), and sequencing (then say welcome).