Curriculum

Curriculum

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.

  1. 1Check Room A
  2. 2Check Room B
  3. 3Consider Room C

Try it yourself

Find the first available room.

Reveal the explanation
  1. Check Room A

    Busy. Continue.

  2. Check Room B

    Free. Return Room B.

  3. 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.