Tracing a flowchart whose arrow loops back through a decision

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Tracing a flowchart whose arrow loops back through a decision

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A flowchart arrow goes from a process box back up to a decision diamond. What should you do in your trace table each time you follow this arrow?
A Add a new row for that pass of the loop
B Overwrite the old row to save space
2. A flowchart has this loop: the diamond asks 'count < 3?', Yes goes to 'count = count + 1', and then the arrow loops back to the diamond. Start with count = 0. How many times is the diamond visited before you take the No exit arrow?
A 4 times (count is 0, 1, 2 and 3)
B 3 times (count is 0, 1 and 2)
3. In the same flowchart, 'count < 3?' with count starting at 0. How many times does the box 'count = count + 1' run?
A 4 times
B 3 times
4. In a flowchart the counter is updated BEFORE the diamond tests it. Which row in the trace table shows the value the diamond actually tests?
A The row showing the counter before it was updated
B The row showing the counter after it was updated
5. A student traces a loop-back flowchart. The diamond test is false, so the No arrow leaves the loop. What does this mean for the trace?
A The exit arrow is reached, so you stop adding loop rows
B You must go back around the loop one more time

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1Diamond: count < 3? Yes -> back to the step before AThe exit arrow: when the test fails, leave the loop and carry on to the output
2Diamond: count < 3? No -> Output count BEach time the Yes arrow loops back to the diamond, add a new row to the trace table for that pass
3The counter is updated before the test, so the diamond sees the new value each time it is visited CStart count <- 0: visits with count 1, 2, 3 for count < 3?
4The diamond is visited once per pass, plus one final visit that takes the exit arrow DA row was missed for a visit to the diamond. Every time the loop-back arrow returns to the diamond, a new row must be added.
5Trace rows: count 1 | count 2 (loop-back arrow followed, but no row added for the third visit) EThe test was read wrongly. 3 < 3 is false, so the No arrow should be taken and the flowchart should exit the loop.
6count = 3: count < 3? is Yes, so loop back again Fcount <- count + 1 then diamond: count < 3?

Definitions

loop-back arrow

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Start: count ← 0 Step: _____ ← count + 1 Diamond: count < 3 ?
2.
Step: count ← count + 1 Diamond: count _ 3 ? Yes → loop back
3.
Start: count ← 0. Step: count ← count + 1 Diamond: count = 3 ? Yes → exit Diamond is visited _ times
4.
Diamond: count < 3 ? Yes → loop back Each pass of the loop adds a new ___
5.
Row 3: count ← 3 Diamond: count < 3 ? __ → exit arrow

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A START
B Set count to 3
C Diamond: count < 3?
D Yes: add 1 to count
E Yes: loop back to diamond
F No: exit arrow, OUTPUT count
Question 2
A Row 1: n=0, test 0<2 Yes
B Row 2: n=1, test 1<2 Yes
C Row 3: n=2, test 2<2 Yes
D Exit arrow: OUTPUT 2
Question 3
A x <- 0
B x <- x + 1
C Diamond: x <- 3
D Yes: arrow back to line 2
E No: OUTPUT x
Question 4
A Test: n < 3, n starts at 0
B Yes passes: n=0, n=1, n=2
C No pass: n=3 (exit arrow)
D Diamond visited 3 times
E So the table needs 4 rows
Question 5
A Set lives to 2
B Diamond: lives > 0?
C Yes: subtract 1, take exit
D No: exit arrow, OUTPUT lives

Answer Key

Tracing a flowchart whose arrow loops back through a decision
Section A: Quick Questions
Q1
A — Add a new row for that pass of the loop
Q2
A — 4 times (count is 0, 1, 2 and 3)
Q3
B — 3 times
Q4
B — The row showing the counter after it was updated
Q5
A — The exit arrow is reached, so you stop adding loop rows
Section B: Match the Pairs
Q1
Diamond: count < 3? Yes -> back to the step before → Each time the Yes arrow loops back to the diamond, add a new row to the trace table for that pass
Q2
Diamond: count < 3? No -> Output count → The exit arrow: when the test fails, leave the loop and carry on to the output
Q3
The counter is updated before the test, so the diamond sees the new value each time it is visited → count <- count + 1 then diamond: count < 3?
Q4
The diamond is visited once per pass, plus one final visit that takes the exit arrow → Start count <- 0: visits with count 1, 2, 3 for count < 3?
Q5
Trace rows: count 1 | count 2 (loop-back arrow followed, but no row added for the third visit) → A row was missed for a visit to the diamond. Every time the loop-back arrow returns to the diamond, a new row must be added.
Q6
count = 3: count < 3? is Yes, so loop back again → The test was read wrongly. 3 < 3 is false, so the No arrow should be taken and the flowchart should exit the loop.
Section C: Definitions
Q1
loop-back arrow — An arrow that returns to a decision diamond. Each time you follow it, add a new row to the trace table so every pass of the loop is recorded, until you take the exit arrow.
Section D: Fill in the Blanks
Q1
Start: count ← 0 Step: count ← count + 1 Diamond: count < 3 ?
Q2
Step: count ← count + 1 Diamond: count < 3 ? Yes → loop back
Q3
Start: count ← 0. Step: count ← count + 1 Diamond: count = 3 ? Yes → exit Diamond is visited 3 times
Q4
Diamond: count < 3 ? Yes → loop back Each pass of the loop adds a new row
Q5
Row 3: count ← 3 Diamond: count < 3 ? No → exit arrow
Section E: Spot the Error
Q1
B — If count starts at 3, the test 3 < 3 is No on the very first visit. The loop-back arrow is never followed. Count should start at 0 so the diamond is visited again and again until count reaches 3.
Q2
C — When n is 2, the test 2<2 is false, so the answer is No, not Yes. The exit arrow is taken here instead of another loop-back. It should say No.
Q3
C — A diamond holds a question with a Yes and a No exit, not an assignment. It should be a test such as x < 3? so the arrow can loop back on Yes and exit on No.
Q4
D — The diamond is visited three times with Yes (n=0, 1, 2) and once more with No (n=3). That is 4 visits, so 4 rows. It should say 4 times.
Q5
C — On Yes the flowchart must follow the loop-back arrow to the diamond so another row is added. The exit arrow is only taken on No. It should say loop back.