GoalExplain how a loop and a decision change the path through a flowchart, and count the outcomes.
New words
loop · a part of a flowchart that repeatsforever loop · a loop with no way out, so it never stops by itselfdecision · a diamond that asks a yes or no questionbranch · one of the two paths that leave a decision
Explanation
Some jobs repeat. In a flowchart, an arrow that goes back up to an earlier step makes a loop. A forever loop has no way out, so it never stops by itself. Most loops contain a decision. The decision asks whether to go round again or to leave. A decision is a diamond with two arrows leaving it, marked yes and no. Each arrow is a branch. A flowchart with one decision has two possible outcomes, because the path depends on the answer.
Worked examples
Lola’s flowchart has one decision, so it has two outcomes. If it is raining she takes an umbrella. If it is not raining she wears a hat.
A lighthouse light flashes all night. Its flowchart is a forever loop: the last step sends the arrow back to the first one, and nothing ever ends the loop.
Check
Cups in the jug
Under 3 cups?
What happens
1
0
yes
pour one cup
2
1
yes
pour one cup
3
2
yes
pour one cup
4
3
no
leave the loop
Following the jug flowchart step by step shows how the loop works. The question is asked again after every pour. The loop stops when the answer is no.
Class activity
Human flowchart (no computer): lay a line of tape on the floor four big steps away from you. Make cards: an oval ‘start’, a rectangle ‘take one step forward’, a diamond ‘Are your toes touching the tape?’ and an oval ‘stop’. Stand on the start card. An adult points to the cards in the order of the arrows. Answer the diamond question honestly each time. If the answer is no, you take a step and go back to the diamond. If it is yes, you stop. How many steps did you take? Move the tape closer or further away and try again.
Practice
1
The stack starts with 2 books. How many books are added before the flowchart ends?
3 books. The stack goes from 2 to 3, 4 and 5 books. At 5 the answer is no, so the loop stops.
2
Draw a flowchart for this game: toss a coin and ask ‘Is it heads?’. If yes, say ‘You win’. If no, say ‘Try again’. How many outcomes does it have?
Start, toss a coin (input), diamond ‘Is it heads?’, yes: show ‘You win’, no: show ‘Try again’, stop. It has 2 outcomes.
3
What does the person wear when the temperature is 20 degrees? What do they wear at 15 degrees?
At 20 degrees they wear a T-shirt. At 15 degrees they also wear a T-shirt, because 15 is not below 15, so the answer is no.
4
A flowchart keeps adding 1 to a counter until the counter is 5. The arrow from ‘add 1’ must go back to a step. Which step, and why?
It must go back to the diamond ‘Is the counter below 5?’, so the question is asked again after every addition. If it went back to the start, the counter would be set again and the loop would never finish.