Ready to begin
No records have been processed. Start with Next step.
Begin with two empty results. Read each score card, apply the two filters independently and append the ID when a condition passes. MonthOfBirth is derived from DateOfBirth; it is not a separate column in our dataset. The source uses SeqNo and TownCity; here the corresponding fields are CardNo and CityTown.
![In the original CardNo order, the May IDs are [3,13,23,25]: Rida, Gopi, Deepika and Geeta.](/images/computational-thinking/week-5/may-list.png)
Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.
Ready
No records have been processed. Start with Next step.
Predict the next change, then step through the list. The original course records remain unchanged.
MayIDs = []
ChennaiIDs = []
foreach X in ScoreRecords:
if month(X.DateOfBirth) == "May":
MayIDs = MayIDs ++ [X.CardNo]
if X.CityTown == "Chennai":
ChennaiIDs = ChennaiIDs ++ [X.CardNo]| Collection | IDs in the dataset scan order |
|---|---|
| May | [3,13,23,25] |
| Chennai | [2,3,5,10,12,17,25,26] |
| Both | [3,25] |
One pass can build both lists. Separate passes can also work, provided the records are available again. A physical Table1-to-Table2 implementation must restore or rename its tables according to its contract before another full scan. A read-only scan of an existing record list does not consume it.
Each unique score record is scanned once, so each qualifying CardNo enters each collection once. Different source orders can produce differently ordered result lists while still representing the same membership. We keep the original dataset order for consistent examples.
Why use two IFs rather than IF…ELSE IF?
A student can satisfy both filters. ELSE IF would prevent a May-born Chennai student from entering the second list.
What should the result be when no student passes a filter?
An empty list [], not an uninitialized variable and not [0].
If you only store names, what problem might occur in a larger class?
Different students may share a name. Stable unique IDs make membership comparisons unambiguous.