ConceptsAll the ideas

Rule Machines

Idea 23of 23Builds onTest the number on the edgeWrite code for a savings plan

Write an IF for a rule

How do you write code that follows a rule with a condition?

Today you'll discover

  • how to turn a rule into a condition
  • what goes on the yes path
  • how to test it

Think firstOrders of $50 or less pay $8 shipping

Which line makes orders of $50 or less pay $8?

Decide first, then press Next. Say what happens on a yes, on a no, and right on the edge.

A flowchart whose diamond starts as a question mark, then reads Is number < 51?. The yes path, marked THEN, leads to ADD 8; the no path, marked skip, leads to do nothing. $30 travels the yes path to $38; $60 travels the no path and stays $60. Along the bottom: $30 to $38, $60 to $60, $50 to $58 (ringed), $51 to $51. The last step asks where a game piece on square 30 moves.

See the whole ideathe big idea and the key word, in one place

The big idea

To write a decision, turn the rule into a yes-or-no condition, then test the edge.

From rule to code'$50 or less pays $8' becomes IF number < 51 THEN ADD 8. Over $50 needs no line of its own: it skips the ADD.

Easy to get wrongCheck the edge with real numbers. $50 should pay $8; $51 should ship free.

Key word

decision
a choice code makes by checking a condition, then running one path or the other

Ready to use it?

  • Write the IF that makes a rule work, and test it.
Practise this idea