Skip to content

Course navigation

For teachersTopic 2.1 · Lesson kit

Algorithms with Selection and Repetition

  • 1 class period
  • 45 minutes each
  • Objective 2.1.A
  • 6 downloads with keys

Downloads

At a glance

Pacing
1 class period of 45 minutes
Learning objectives
2.1.A
Essential knowledge
2.1.A.12.1.A.22.1.A.32.1.A.42.1.A.5
Materials
Projector and the Decide and Repeat slide deckWhiteboard and markersPrinted Decide and Repeat puzzle worksheet (answer key for you) and exit ticket

45 minutes a day

Agenda

Day 145 minutes

  • Warm-up
  • Direct instruction
  • Guided practice
  • Activity
  1. 0:00–0:033 minWarm-upsame list, different day (slide 2)
  2. 0:03–0:118 minDirect instructionsequencing, selection, repetition (slides 3–7)
  3. 0:11–0:187 minDirect instructionselection and the condition (slides 8–10)
  4. 0:18–0:268 minDirect instructionrepetition, passes, and infinite loops (slides 11–13)
  5. 0:26–0:326 minDirect instructionwords and flowcharts (slides 14–16)
  6. 0:32–0:386 minGuided practiceorder matters (slides 17–19)
  7. 0:38–0:457 minActivityClosure and exit ticket (slides 20–21)

Overview

One class period. Students meet the three building blocks of algorithms: sequencing, selection, and repetition (2.1.A.1 to 2.1.A.3). They trace algorithms with a decision and with a loop, show them as numbered steps and as flowcharts with a decision diamond (2.1.A.4), and see that changing the order of the blocks changes the result (2.1.A.5).

Stay inside the topic boundary. Selection and repetition are taught as ideas in plain-language steps and flowcharts; the Java if statement is Topic 2.3 and loops are Topics 2.7 and 2.8. The only Java is two short sequencing examples, plus the Math.abs and indexOf methods that students already know from Topics 1.11 and 1.15.

Teacher note

The slides are the Decide and Repeat deck (21 slides, with speaker notes); slide numbers below refer to it. The puzzle worksheet has 10 questions and takes about 35 minutes. Do question 1 after the building-block segment and question 2 after the repetition segment if you want to check understanding in class; the rest (questions 3 to 10) is homework. In every written algorithm on the worksheet, a “Repeat until” step checks its goal before each pass and stops as soon as the goal is true; say this aloud once.

Examples are in the topic’s examples/ folder. Use BonusThenDouble and DoubleThenBonus for the order-matters segment. AbsDecision, IndexOfSearch, and FinalScoreWrong are in the study guide and need not be shown in class.

Warm-up: Same list, different day

Show slide 2, the morning routine. Students talk with a partner: which steps happen every day exactly once, and which can change? Take two or three answers. Look for “the umbrella step” (depends on rain) and “brushing” (depends on how long it takes). Do not name the building blocks yet.

Direct instruction: Sequencing, selection, repetition

  1. Goals (slide 3).
  2. Three building blocks (2.1.A.1, slide 5). Sequencing is steps done in order, each once. Selection is a decision that chooses the next step; another name is decision making. Repetition is repeating steps until a goal is reached; another name is looping, and the repeated steps are a loop.
  3. Find them in the routine (slide 6). Go down the table: steps 1 and 4 are sequencing, step 2 is selection, step 3 is repetition. Stress that the whole list is still a sequence. Selection and repetition live inside the order.
  4. A recipe that stirs three times (slide 7). Three separate “Stir” steps are still sequencing, and three is a guess. “Stir until there are no lumps” is repetition because the goal decides when to stop.

Misconception: Writing a step several times is repetition

Students list the same step three times and call it a loop. Ask: “What if the batter needs twenty stirs?” Real repetition is one instruction plus a goal.

Direct instruction: Selection and the condition

  1. A decision chooses the next step (2.1.A.2, slide 9). Selection depends on a true or false decision; the question is the condition. Walk the flowchart with a rainy day and a sunny day: each takes one arrow out of the diamond.
  2. Pause and try (slide 10). Students trace “if the score is at least 70, say pass; otherwise say try again” for 85, 70, and 64: pass, pass, try again. 70 is the case to discuss, because “at least” includes the boundary.

Misconception: A decision that is not a true-or-false question

“Decide what to wear based on the weather” cannot be followed by a literal reader, because the weather is not true or false and no step says what to do for each case. A decision needs a condition that is true or false, such as “Is it raining?”

Direct instruction: Repetition, passes, and infinite loops

  1. A loop repeats until its goal is reached (2.1.A.3, slide 12). Trace the jug table row by row: check the goal first, pour 3 if it is not met. Each time through is a pass. It takes 4 passes and the jug ends at 12 cups, not 10, because the check happens before each pass.
  2. A goal that is never reached (slide 13). Starting at 0 and adding 2 until x is 7 jumps from 6 to 8 and never equals 7. This is an infinite loop. Give students 30 seconds to change one thing so the loop stops (change 7 to 8, or start x at 1, or add 1). Collect more than one fix.

Misconception: Repeat until means stop when the goal is passed

The goal is checked for being exactly true. In the 6-to-8 example, x passes 7 without ever stopping on it. Ask students to write the values after each pass before they decide the loop stops.

Misconception: A backward arrow can point anywhere

If the arrow back in a flowchart goes to a step that resets the value (for example, back to “Set savings to $0”), every pass undoes the last one and the goal is never reached. Have students trace two passes before trusting a flowchart.

Direct instruction: Words and flowcharts

  1. Flowchart pieces (2.1.A.4, slide 15). Start and Stop, a step box, a decision diamond with a true arrow and a false arrow, and an arrow back for repetition.
  2. The jug loop as a flowchart (slide 16). A loop is a decision plus an arrow back. The diamond asks about the goal before each pass, and the true arrow leaves the loop. Have students match each line of the written version to a shape.

Guided practice: Order matters

  1. Add, then halve (2.1.A.5, slide 18). Show BonusThenDouble and DoubleThenBonus. Students predict the two outputs (Points: 30 and Points: 25), then run or reveal them. Same two steps, different order, different result. The same is true when a step moves inside or outside a loop or before or after a decision.
BonusThenDouble
int points = 10;
points += 5;
points *= 2;
System.out.println("Points: " + points);
DoubleThenBonus
int points = 10;
points *= 2;
points += 5;
System.out.println("Points: " + points);
  1. Where does the decision go? (slide 19). Version A checks the water once, after the loop. Version B checks it inside the loop on every dish, so only version B can drain the sink more than once. Students answer with a partner, then share.

Misconception: Same steps, same result

Students check that an algorithm has all the right steps and stop there. Ask every time: “What has already happened by the time this check is made?” Trace with a value near the edge.

Independent practice: Independent practice

Hand out the Decide and Repeat puzzle worksheet. If time allows, students start question 1 (sort the steps) in class. Questions 3 to 10 are homework. Question 3 settles the Think First guess from question 2’s page (add the bonus, then double: 90). Question 6 fixes a loop that never stops.

Closure: Closure and exit ticket

Show slide 21. Partners finish the sentence starter: “Selection _ once and picks a path, but repetition _ until ___.” Then give the exit ticket (about five minutes). Question 1 checks the three building blocks (2.1.A.1 to 2.1.A.3), question 2 checks tracing a loop (2.1.A.3), and question 3 checks that order changes the result (2.1.A.5). Slide 20 (vocabulary) is for students to keep as a reference. Re-teach the weakest question at the start of Topic 2.2.

Exit ticket

Question 1 · Multiple choice

Which building block does the step “If the pizza box is empty, throw it away” show?

  1. Sequencing, because it is one step in the list
  2. Selection, because a true-or-false decision chooses whether the step happens
  3. Repetition, because the step could happen many times
  4. None of these, because it is not a step in an algorithm
Check your reasoning

B. The step asks a question that is true or false, and the answer decides what happens. That is selection. A is wrong because this step does not always happen; a decision controls it. C is wrong because repetition means repeating steps until a goal is reached, and nothing here repeats. D is wrong because it is a step that helps get a job done.

Question 2 · Tracing

Trace this algorithm. What does it say at the end, and how many passes did the loop make?

1. Set n to 1.
2. Repeat until n is at least 20:
3.     double n.
4. Say n.
Check your reasoning

It says 32, and the loop makes 5 passes.

Pass n before At least 20? n after
1 1 no 2
2 2 no 4
3 4 no 8
4 8 no 16
5 16 no 32

After pass 5, n is 32, the goal check is true, and the loop stops. Answers of 20 (stopping exactly at the goal) or 16 (stopping one pass early) are common mistakes. A complete answer gives 32 and 5 passes.

Question 3 · Short answer

An algorithm for a game score has two steps: “Subtract 4 from the score” and “Triple the score.” The score starts at 10. What is the final score if the steps are done in the order given? What is it if the two steps are swapped? What does this show about algorithms?

Check your reasoning

Model answer: In the order given, 10 minus 4 is 6, then 6 tripled is 18. Swapped, 10 tripled is 30, then 30 minus 4 is 26. The two orders give different results, so the order in which steps are done changes the result of an algorithm.

A complete answer gives 18 and 26 and says that order matters.