Idea 14of 23Builds onSort numbers with an IF
A question inside a question
How can code sort numbers into three groups?
Today you'll discover
- how an IF can sit inside an IF
- how to follow a decision tree
- why some numbers meet two questions
Think firstLibrary sorter: trolley 1, 2 or 3
A book has shelf number 25. Which trolley does it go to?
Decide first, then press Next. Follow one path down, one diamond at a time.
A flowchart with two diamonds. The first asks Is number > 20?. Its yes path leads to a second diamond, Is number even?, with yes to SET 1 and no to SET 2; its no path leads straight to SET 3. 22 travels yes, yes to trolley 1; 8 travels no to trolley 3. Along the bottom: 22 to trolley 1, 8 to trolley 3, 25 to trolley 2, 30 to trolley 1. The last step asks how many digits 10 has, from a tree that asks under 10, then under 100.
See the whole ideathe big idea and the key word, in one place
The big idea
An IF can sit inside another IF; two questions in a row make a decision tree.
Three trolleys
Over 20 and even goes to trolley 1, over 20 and odd to trolley 2, and 20 or less to trolley 3.
- 221
- 252
- 83
- 301
Easy to get wrongA yes to the first question is not always the end. Keep going until there are no more questions.
Key words
- nested
- placed inside another one, like an IF inside an IF, or an IF inside a loop
- decision tree
- questions that lead to more questions, branching until each path ends in an answer
Ready to use it?
- Follow a number through a question inside a question.