ConceptsAll the ideas

Rule Machines

Idea 10of 23Builds onA condition is yes or no

IF … THEN runs only on a yes

What does code do when the answer to its question is no?

Today you'll discover

  • what IF … THEN does
  • what happens on a no
  • how the code carries on after

Think firstFood drive: 10 or more cans get 5 more

A class brings 6 cans. What does the code output?

Decide first, then press Next. On a no, follow the path marked skip.

A flowchart: an orange diamond asks Is number > 9?. The yes path, marked THEN, leads to ADD 5; the no path, marked skip, leads to a dashed box that says do nothing. Both meet at OUTPUT. 12 travels the yes path and comes out 17; 6 travels the no path and comes out 6. Along the bottom: 12 to 17, 6 to 6, 9 to 9, 15 to 20. The last step asks about a $20 book when books over $20 get $4 off.

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

The big idea

IF … THEN runs its lines only when the answer is yes; a no skips them.

The food drive12 cans: yes, so 12 + 5 = 17. 6 cans: no, so it stays 6. 9 cans: no, because 9 is not more than 9.

Easy to get wrongA no does not stop the program. It only skips the lines between THEN and END.

Key word

IF … THEN
code that runs some lines only when its condition is true, and skips them when it is false

Ready to use it?

  • Say what an IF … THEN outputs on a yes and on a no.
Practise this idea