Flowchart and trace table – selection and iteration

Computer ScienceAlgorithms & Problem SolvingAges 13–14

Loading…

Use with my class ✨ Customize with AI Report a problem

The same algorithm is shown side by side as a flowchart and as pseudocode, Python or blocks. Students set the inputs and step through IF … ELSE, nested IF, FOR, WHILE and REPEAT … UNTIL loops while the path taken lights up and a trace table fills row by row with a loop-pass counter. Built-in tasks cover totalling, counting, maximum, minimum and average, compound conditions with AND/OR/NOT, De Morgan's laws, short-circuit evaluation and event handlers, and an edit mode lets students build or fix an algorithm and check it against test data.

Lesson: Control structures: selection and iteration

What it shows

Algorithms are built from three control structures: sequence, selection and iteration. This simulation runs an algorithm one instruction at a time and shows the same program as a flowchart and as pseudocode, Python or blocks. Each step adds a row to the trace table, the standard way to dry-run an algorithm by hand. Count-controlled FOR loops, condition-controlled WHILE loops, which may run zero times, and REPEAT … UNTIL loops, which always run at least once, can be compared directly, together with truth tables, De Morgan's laws and short-circuit evaluation.

How to use

Choose a Task, check the Inputs and click Step. The shape just run is highlighted, the bold arrow shows the branch taken and a new row appears in the trace table. Click Play to run automatically. Switch Code view between Pseudocode, Python and Blocks. Click Edit algorithm to add, change or delete steps, then click Run tests to check your algorithm against the test data.

Parameters you can change

  • Task Selection IF … ELSE: pass or fail, Nested IF: grades A, B, C, FOR loop: totalling, FOR loop: counting, Maximum, minimum and average, WHILE loop with a rogue value (−1), REPEAT … UNTIL: input validation, Compound conditions AND, OR, NOT, De Morgan's laws, Short-circuit evaluation, Event handlers: click and key press, Challenge: fix the maximum algorithm, Challenge: count negatives, Blank: build your own algorithm
  • Inputs, separated by commas (empty = the task's own inputs)
  • Code view Pseudocode, Python, Blocks
  • Short-circuit AND/OR
  • Run speed 1–10 steps/s

Questions to explore

  1. How many times does the body of a FOR loop run when n is 0?
  2. Why does a REPEAT … UNTIL loop always run at least once while a WHILE loop may not run at all?
  3. Why does the maximum algorithm fail when every input is negative, and how can you fix it?