Teaching article

An if instruction needs a condition the reader can test

Define a test that selects an action.

Use a visible shape property to choose between two actions. A condition such as has a triangle gives the interpreter evidence to inspect, unlike an undefined judgement such as looks special.

Use a condition that can be decided from the available input. An undefined term such as special makes the branch difficult to execute consistently.

Let the input decide the branch

To hand: Cards marked with shapes.

  1. State the condition.
  2. Check one card.
  3. Follow the matching branch.

If the card has a triangle, place it in tray A; otherwise use tray B.

A condition needs an observable rule. Which evidence selected the branch?

Use two large shape examples.

Resources

Further reading

Read next

Explore Coding and computational thinking. Browse all teaching articles.