Science / Grade 7
Stop at the first match
Learning goal: Trace an ordered search, separate value from position, repair a missing stop and handle empty or nonmatching lists.
Before you start: Read an ordered list, follow an If condition and use a variable to hold a result. Item numbers in this paper model start at 1.
Read or print this lesson What to practiceThe video could not load. The transcript is still available below.
Next: your worksheet
First Match: Trace Before You Choose
Checking sign-in...
Read the transcript
Saved reading place
Video transcript and practice. Reading or printing does not count as playback time or an assessed grade.
1. The robot does not need a contest
Video: 0:00

Our delivery robot needs the first order with a value of at least two. It does not need the biggest order, the last order, or a grand total with a tiny trophy. First means the earliest matching position in the given list. We will inspect values in order, test each one, and stop the scan when we find a match. Then the rest of the program can use that result. You should already recognize a list, a stored value, and an If condition. Our instructions are a paper model, not the syntax of a particular programming language.
2. Position and value do different jobs
Video: 0:39

Start with the list one, three, four. Keep that order. One is less than two, so it fails our rule. Three is at least two, so it matches. Copy three into the result and stop scanning. Do not inspect the later four. Notice that the matching value is three, while its position is item two. We number items from one in this paper model. Position tells us where the value was; the copied value tells the robot how much to deliver. Reporting two because it was the second item would answer a different question.
3. Include the boundary
Video: 1:19

Now inspect zero, one, two, four. Zero fails. One fails. Two passes, because at least two includes exactly two. Copy two, then stop this scan. We made three comparisons, even though the result is two and the list contains four items. These are three different quantities: comparisons, selected value, and list length. The later four is not inspected. A trace should record what actually ran, not every value you can see on the page. If you change the condition to greater than two, you change the question and get a different search.
4. Stop the scan, not the program
Video: 2:03

Read the shape of these pseudo-instructions. Set the result to zero before the loop. For each value in order, test whether it is at least two. Inside the successful If branch, copy that value and stop this scan. End marks where a block closes; End alone is not an instruction to leave a running scan early. After the loop, report the result. That report still runs after a successful stop. Our robot should stop searching, not shut down the entire delivery desk. In Route Coder, the matching block is called Stop scanning orders.
5. No match needs a clear fallback
Video: 2:44

What if every value fails? For one, zero, one, inspect all three positions. No match replaces the starting result, so it stays zero. Zero is a fallback in this contract, not a claim that we found a matching zero. For an empty list, there are no items and no comparisons at all, but the same fallback remains. Both cases still continue to the report after the loop. This fallback works here because zero cannot satisfy our rule. A search where zero could be a valid match would need a separate way to distinguish found from not found.
6. Equal values are separate positions
Video: 3:25

Consider two, two, four. The first two already satisfies the rule. Copy it and stop after one comparison. The second two has the same value but sits at a different position. It is not inspected, and it does not earn a second check mark. This is a search for one first match, not a count of every matching item. If we kept copying each match instead, a later value could replace the earlier result. A list with one early match and a different later match is useful for exposing that missing stop.
7. Pause: trace a fresh list
Video: 4:04

Pause with a new list: one, zero, four, two. Keep the same rule, first value at least two, and the same zero fallback. State the result, the number of comparisons, and any items that are not inspected. Explain why the result is not the position number and why the later two does not replace it. Then try an empty list. How many comparisons happen, what result remains, and does the report after the loop still run? You can point, speak, or write your trace. Continue when you have reasons for your choices.
8. Check the work that actually ran
Video: 4:43

For the fresh list, one fails and zero fails. Four passes, so copy four from item three and stop. The result is four, not three. Three is the position and also, in this case, the number of comparisons. The later two is not inspected. For an empty list, zero comparisons happen and the fallback stays zero. The report after the loop still runs in both cases. If your trace inspected the later two, look for the missing stop. If your trace stopped before copying four, check the order of the two successful-branch instructions.
9. Same values can give a new result
Video: 5:25

Fun fact: three followed by two and two followed by three have the same values, the same length, and the same sum. Yet this first-match search selects three from one list and two from the other. Order is part of the problem, not decoration. Continue to the first worksheet for a different trace, then repair the faulty scan on the second worksheet. After that, use Route Coder to build, step through, and test your program on several routes. A successful example is a start; empty lists, boundary values, and repeated matches help check whether the reasoning still works.
Show your understanding
You can point, explain aloud, draw or write.
- Trace the first qualifying value, its position and the number of comparisons, including empty and no-match lists.
- Repair a missing stop without skipping the report after the scan, and explain why first does not mean largest or last.
Try it yourself
Pause at [1, 0, 4, 2]. State the result, comparison count and uninspected items. Then explain the empty-list trace.
Continue to the tracing worksheet, then repair the missing stop and try Route Coder. Item numbers in this paper model begin at 1.
Next: your worksheet
First Match: Trace Before You Choosehttps://s3u.com/sc7s1
Lesson: https://s3u.com/lessons/stop-at-the-first-match