Count Items That Match a Rule
Combine a repeat over cards with a conditional count.
Supplied materials
- Paper and pencil; an adult may read aloud. No device, account or purchase is needed.
Learn the idea
We can use a condition inside a repeat. The repeat visits each card once, and the condition decides whether that visit adds to a count. Start the count before visiting cards. A card that fails the condition still gets visited, but it does not add to the matching count.
Supplied list in order: star, circle, star, triangle, star. Algorithm: set matches to 0; for each card, if its shape is star, add 1 to matches; after all cards, show matches. A trace records the count after each card. Keep the count from the previous row.
- Write the five-card list and start a matches column at 0.
- For each card, answer is it a star?
- Add 1 only on true rows and carry the old count on false rows.
- Read the final count and compare it with a direct count of stars.
See the method in action
Counts after the five cards are 1, 1, 2, 2, 3. The final result is 3 matching cards, even though 5 cards were visited.
Check your reasoning
Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.
See the answer and explanation
2
The running counts are 0, 1, 2, 2. Exactly two cards meet the star condition.
Take it further
Change the condition to shape is circle in the original list. Expected trace: 0, 1, 1, 1, 1, so the final result is 1.
Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.
Check the subject sources
These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.