Learn
B1.1.4 | TRACING FLOWCHARTS
01 | FOLLOW THE ROUTE, NOT YOUR INSTINCT
A flowchart is a map of an algorithm. Its symbols show actions and decisions; its arrows tell you which action happens next. Tracing means acting as the algorithm’s executor, one step at a time.
The IB command term trace means to follow and record the actions of an algorithm. You may need to record changing variable values, decisions, input consumption and outputs. Guessing the final answer without following the route can miss a loop or an important boundary case.
This common SL/HL lesson starts with the symbols, then works through sequence, selection, counted repetition, pre-condition loops and post-condition loops. You can trace all five examples interactively.
02 | SIX SYMBOLS YOU NEED
START / END: a rounded terminal marks entry or termination.
PROCESS: a rectangle contains an operation, such as Total ← 0.
INPUT / OUTPUT: a parallelogram reads data or produces an output.
DECISION: a diamond tests a condition; follow the labelled branch.
FLOWLINE: an arrow shows the direction of execution.
CONNECTOR: a labelled circle links to the matching connector, avoiding a long or crossing line.
A shape tells you the kind of action, but its text tells you what to do. Two parallelograms can have different roles: INPUT Number reads a value; OUTPUT Number displays the current value.
03 | ARROWS AND CONNECTORS CONTROL THE PATH
Begin at START and follow each arrowhead. A decision normally has two outgoing branches, labelled YES/NO or TRUE/FALSE. Evaluate the condition using the current values, then follow only the matching branch.
The line’s direction matters more than where the next box appears on the page. A loop arrow may take you upwards to an earlier symbol. Do not jump to the nearest box or follow both outcomes of a decision.
A connector transfers flow to the matching label. For example, a line ending at connector A continues from the corresponding A elsewhere in the same chart. It does not reset variables or perform a calculation. A line crossing without a junction mark does not automatically connect two routes.
04 | VARIABLES ARE CURRENT VALUES
A variable is a named storage location whose value can change. In Count ← Count + 1, first read the old Count, add one, then store the result back in Count. If Count was 2, it becomes 3.
The arrow ← denotes assignment in these diagrams. It is not a claim that Count is mathematically equal to Count + 1. Similarly, Total ← Total + Number reads the old total and adds the current number, producing a new running total.
A decision such as Count ≤ Limit compares values; it does not change them. A variable that has not been assigned a value is “not set” in the trace, not automatically zero.
05 | INPUTS, OUTPUTS AND PROMPTS
INPUT Number consumes the next supplied input and stores it in Number. Reaching that symbol a second time consumes the next input, rather than reusing the first one. OUTPUT Number displays the value already stored and does not ask for another.
An output such as OUTPUT "Enter a number" is a prompt: it displays literal text. It is separate from reading the response. Quotation marks distinguish literal text from a variable name.
Record outputs in the order they occur, including repeated outputs. If a flowchart outputs Count three times, the output sequence matters; do not record only Count’s final value.
06 | SET UP A TRACE TABLE
| Step | Symbol / action | Current values after action | Decision or output |
|---|---|---|---|
| 1 | START | Number not set | Begin |
| 2 | INPUT Number, supplied value 4 | Number = 4 | Input 4 consumed |
| 3 | Double ← Number × 2 | Number = 4; Double = 8 | No output yet |
| 4 | Result ← Double + 1 | Result = 9 | No output yet |
| 5 | OUTPUT Result | Values unchanged | Output 9 |
This lesson records one row for every executed symbol, including decisions and START/END. Other tasks may provide a table that records only changes or selected steps. Follow its headings and instructions, while still checking every action mentally.
07 | SEQUENCE: DOUBLE AND ADD ONE
Sequence means actions happen in the arrow order. Read one number, double it, add one and output the result. Follow the actual assignments: do not replace the calculation with a different expression that changes the order.
For input 4, Double becomes 8, Result becomes 9 and the only output is 9. For input −2, Double becomes −4 and Result becomes −3. The chart works with the supplied number; it does not assume it is positive.
08 | SELECTION: WHICH BRANCH?
Selection chooses a route using a condition. In this fictional admission rule, an age of at least 12 produces Allowed; a lower age produces Not yet. We assume a valid non-negative integer age has already been supplied.
For Age = 12, Age ≥ 12 is true, so follow YES and output Allowed. For Age = 11, it is false, so follow NO and output Not yet. Both branches rejoin at END; exactly one message is output for each run.
09 | TEST THE BOUNDARY EXACTLY
| Age | Age ≥ 12? | Branch | Output |
|---|---|---|---|
| 11 | False | NO | Not yet |
| 12 | True | YES | Allowed |
| 13 | True | YES | Allowed |
The equality part of ≥ determines what happens at 12. Reading it as > would give the wrong answer at precisely that boundary. Write down the current comparison rather than answering from what you expect the rule to be.
A decision diamond is a question about the current state. It does not assign 12 to Age, and following NO does not mean the whole algorithm has failed; it selects the other defined behaviour.
10 | LOOPS: FOLLOW THE RETURN ARROW
A loop repeats a section of an algorithm. The repeated actions are the loop’s body. For example, a body might output Count and then increase Count by one. The condition determines whether to enter, repeat or leave that body.
On returning to a decision, evaluate it again using the updated values. Its answer can change. Carry the state forward; do not reset a variable unless an executed process explicitly assigns it again.
A loop is not automatically infinite because an arrow points backwards. Look for the value that changes and how that change can eventually cause an exit.
11 | COUNTED REPETITION: OUTPUT 1 TO LIMIT
This chart explicitly represents a counting loop using an initial value, a comparison and an increment. It outputs the integers from 1 through Limit, inclusive. Limit is a supplied whole number from 0 to 6 in the explorer.
The body is OUTPUT Count followed by Count ← Count + 1. The decision is checked before the body. For Limit = 3, Count starts at 1, and the loop outputs 1, 2, 3. After the third increment Count is 4; 4 ≤ 3 is false, so the chart ends without outputting 4.
12 | A COMPLETE COUNTED-LOOP TRACE
| Action | Count after action | Condition / new output |
|---|---|---|
| Initialise with Limit = 3 | 1 | No output |
| Test Count ≤ Limit | 1 | 1 ≤ 3: YES |
| OUTPUT Count | 1 | Output 1 |
| Increment | 2 | No output |
| Test; output; increment | 3 | 2 ≤ 3: YES; output 2; then Count becomes 3 |
| Test; output; increment | 4 | 3 ≤ 3: YES; output 3; then Count becomes 4 |
| Test and leave | 4 | 4 ≤ 3: NO; END |
The table compresses repeated actions into labelled rows; the explorer shows every symbol separately. Notice the difference between the final variable value, 4, and the final output, 3.
For Limit = 0, the first comparison is 1 ≤ 0, which is false. The body runs zero times and there are no outputs. START and END are control symbols, not printed messages.
13 | PRE-CONDITION LOOP: TOTAL UNTIL ZERO
A pre-condition loop checks its continuation condition before each execution of the body. Here zero is a sentinel: an input value indicating that entry should finish. The chart adds nonzero values and outputs their total when zero is read.
Total is set to 0 before the first input. If Number ≠ 0, add Number to the old Total, then read another Number. Return directly to the decision, keeping the running total. When Number is 0, follow NO to OUTPUT Total and END.
14 | TRACE THE RUNNING TOTAL
| Event for inputs 4, 7, 0 | Number | Total | Effect |
|---|---|---|---|
| Initialise | Not set | 0 | No output |
| Read first input | 4 | 0 | Next comparison is true |
| Add current number | 4 | 4 | 0 + 4 stored in Total |
| Read next; add | 7 | 11 | 4 + 7 stored in Total |
| Read sentinel | 0 | 11 | Condition is false; no addition |
| Output total | 0 | 11 | Output 11 once |
Total ← Total + Number keeps what was accumulated and adds the new contribution. Total ← Number would replace the accumulated amount, losing the earlier inputs.
The sentinel is read but not added, because the false branch leaves before the addition. Zero would not change this sum anyway, but the route matters: a count of processed values must not accidentally count the sentinel.
15 | ZERO FIRST AND THE MISSING UPDATE
If the first input is 0, the condition is false immediately. The body runs zero times, and the chart outputs the initial total of 0. A pre-condition loop can therefore skip its body completely.
If the second INPUT Number inside the body were removed, Number would never change after a nonzero first input. The same true comparison and addition would repeat indefinitely.
If Total ← 0 were placed inside the repeated body, earlier contributions would be lost. Trace the arrows to see which initialisations happen once and which operations repeat.
16 | POST-CONDITION LOOP: GET A POSITIVE NUMBER
A post-condition loop performs its body before testing whether it should stop. Here the body reads Number. The decision asks whether Number > 0. YES leaves the loop; NO returns to the input.
For inputs −2, 0, 5, the chart reads −2 and repeats, reads 0 and repeats, then reads 5 and exits. It outputs 5 once. The input body runs at least once; the output is outside the loop.
The stopping condition is not a continuation condition. In this chart, true means stop repeating. Always follow the labels rather than assuming YES must loop.
17 | COMPARE THE LOOP ROUTES
| Feature | Pre-condition total example | Post-condition positive-input example |
|---|---|---|
| Test position | Before the repeated addition/read body | After the input body |
| Meaning of true | Continue while Number ≠ 0 | Stop when Number > 0 |
| Minimum body executions | Zero | One |
| Exit arrow | NO | YES |
| Variable update | Read the next Number inside the body | Read Number before each test |
These examples have different purposes as well as different loop structures. Do not claim they produce equivalent results for the same data. To trace any chart, locate its body, test position, updated values and actual exit branch.
18 | CONNECTORS DO NOT CHANGE VALUES
A connector is a visual continuation, not an input or processing step. If an arrow leads to connector A, resume at its matching A and retain the current values. A connector can be used to keep a long chart readable.
BEFORE CONNECTOR A
Total = 11. Follow the arrow into the circle labelled A.
MATCHING CONNECTOR A
Resume from the matching A. Total is still 11.
NEXT ACTION
OUTPUT Total displays 11. The connector has performed no arithmetic.
If labels or arrows are missing and the route is genuinely ambiguous, do not invent a jump. Check the supplied diagram or explain the ambiguity.
19 | INTERACTIVE: EXECUTE ONE SYMBOL AT A TIME
Choose a chart and enter comma-separated whole-number inputs. Use Load / restart trace to prepare a fresh run, then predict each next action before executing it. The pink symbol is the most recently executed symbol, and the table records values after that action.
Sequence accepts one input from −20 to 20; admission accepts one age from 0 to 120; counting accepts one Limit from 0 to 6. The total example needs a zero sentinel, and the positive-input example needs a positive value. Each list may contain up to eight values from −20 to 20. Values after termination are not consumed.
| Step | Symbol / action | Current values | Decision / input / output |
|---|
The next-step button stays below the growing trace table, so you can continue where you finish reading. This is a bounded teaching simulator, not a general flowchart interpreter.
20 | PREDICT, TRACE, THEN CHECK
In your book, predict the output and final values before loading each example: sequence with 6; admission with 11 and then 12; counting with 0 and then 3; total with 4, 7, 0; positive input with −2, 0, 5.
For each decision, write the comparison using the current values and mark its result. For each input, cross out exactly one consumed value. For each output, append it to a separate output list.
Reveal the expected results
Sequence 6: Double = 12, Result = 13, output 13. Admission 11: Not yet; admission 12: Allowed. Counting 0: no outputs, Count = 1; counting 3: outputs 1, 2, 3, final Count = 4. Total 4, 7, 0: Total = 11 and Number = 0, output 11. Positive input −2, 0, 5: Number = 5, output 5, three inputs consumed.
21 | DIAGNOSE THE ROUTE, NOT JUST THE ANSWER
A wrong trace can come from reading the wrong branch, failing to update a value, consuming the wrong input or recording a calculation as output. Locate the first incorrect action, because later values may all depend on it.
For the counting chart, changing ≤ to < with Limit = 3 removes output 3. Removing the increment prevents Count changing and creates a non-terminating loop whenever the initial comparison is true.
For the positive-input chart, changing > 0 to ≥ 0 accepts zero. That is a changed rule, not merely a different way to draw the same algorithm.
22 | COMMON TRACING MISTAKES
| Mistake | Correction |
|---|---|
| Resetting a variable when a loop arrow returns | Only an executed assignment changes it. |
| Following both decision branches | Evaluate the condition and follow the matching branch only. |
| Assuming every YES arrow repeats | Read the actual branch destination. |
| Treating an input prompt as supplied data | OUTPUT displays a prompt; INPUT reads the next value. |
| Printing every process result | Record output only at executed OUTPUT symbols. |
| Giving only the final variable values | Also record the actions, decisions and output sequence requested. |
| Counting a sentinel as ordinary data | Follow the condition before processing it. |
23 | TRANSFER TASK: COUNT VALUES ABOVE FIVE
Adapt the total-until-zero method on paper. Keep a running Count initially 0. For each nonzero input, increase Count only if Number > 5, then read the next input. When zero is read, output Count.
Sketch or describe the extra decision and trace inputs 4, 8, 5, 9, 0. Highlight the difference between the loop condition, which checks for the sentinel, and the selection inside the body, which decides whether to count this value.
Reveal a trace outline
Count starts at 0. Input 4 is nonzero but not above five, so Count stays 0. Input 8 increases it to 1. Input 5 does not meet > 5. Input 9 increases it to 2. Input 0 leaves the loop before the inner selection. Output 2. The algorithm consumes five inputs, counts two qualifying values and outputs once.
24 | A RELIABLE TRACING ROUTINE
Find START, list the supplied inputs and mark all variables not yet assigned. Execute one symbol, update the current state, record any decision or output, then follow its arrow. Repeat until END or until the algorithm needs unavailable input.
If no input is available, do not invent one. If the chart never reaches END, explain the repeated route and why its state cannot produce an exit.
You should now be able to recognise the standard symbols and follow sequence, selection and different loop structures, recording variables and outputs accurately.