ConceptsAll the ideas

Rule Machines

Idea 13of 23Builds onGreater than, less than, equal to

Sort numbers with an IF

How can code put numbers into groups?

Today you'll discover

  • how an IF can sort
  • how to test for even
  • how to check every tray

Think firstTray 1 for even numbers, tray 2 for odd

Which tray does 33 go to?

Decide first, then press Next. Each number answers one question and lands in one tray.

A flowchart: a diamond asks Is number even?. The yes path leads to SET 1, tray 1; the no path leads to SET 2, tray 2. 14 travels the yes path; 33 travels the no path. Along the bottom: 14 to tray 1, 33 to tray 2, 20 to tray 1, 7 to tray 2. The last step asks where 50 goes when tray 2 is for numbers over 50.

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

The big idea

An IF can sort numbers: each number answers the question and goes into one group.

Sorted

Even numbers 14 and 20 go to tray 1. Odd numbers 33 and 7 go to tray 2.

  1. 14tray 1
  2. 33tray 2
  3. 20tray 1
  4. 7tray 2

Easy to get wrongA big number is not always even. Only the ones digit decides: 33 is odd, and 50 is even.

Key word

sort
to put things into groups by a rule, such as even numbers in one tray and odd in another

Ready to use it?

  • Sort numbers with a condition, and say which group each goes in.
Practise this idea