Walk Through a List One Item at a Time
Scenario
The schedule lists Room A as busy, Room B as free, and Room C as free.
- 1Check Room A
- 2Check Room B
- 3Consider Room C
Try it yourself
Find the first available room.
| Case | State after the step |
|---|---|
| Check Room A | — |
| Check Room B | — |
| Consider Room C | — |
Reveal the explanation
- Check Room A
Busy. Continue.
- Check Room B
Free. Return Room B.
- Consider Room C
This item is skipped because the first match was found.
To collect all free rooms, replace the early return with “add this room to the results” and continue.
Your turn
Trace a list with one occupied room and two free rooms. Collect all free rooms.
Common mistake Returning the first match when the task asks for every match.
Check your work
The result contains both free rooms in the original order.
This browser could not save your progress. Changes last until you leave the page.