What must you do before changing an existing algorithm?
Read and trace it until you understand what it currently does
Define a logic error
An error where the program runs without crashing but gives the wrong result
How many times does FOR i ← 0 TO 9 run?
10
Flowcharts have no loop symbol. What do you draw instead?
A decision diamond with an arrow going back
What is the most ELSE parts one IF statement can have?
One
Name the two ways to find an error in an algorithm
A dry run with a trace table, and testing with test data
Rewrite END FOR in our pseudocode style
NEXT i
Which process box does a FOR loop hide?
The counter increment, e.g. c ← c + 1
Task 1.1:
INPUT n
IF n > 10 THEN OUTPUT n * 2
ELSE OUTPUT n + 5
What is the output for input 10?
15 (10 is not greater than 10, so the ELSE part runs: 10 + 5)
Fix this line from a "find the smallest" algorithm: smallest ← -99999999
smallest ← 99999999 (start very high so the first value replaces it)
total ← 0, then FOR i ← 1 TO 4: total ← total + i. Trace total.
1, 3, 6, 10. The final total is 10
Write the decision box for FOR c ← 0 TO 2
Is c ≤ 2? Yes → run the loop body, No → exit the loop
Edit total ← a + b so the algorithm also adds a third number
Add INPUT c, then change the line to total ← a + b + c
This line should square n: square ← n × 1. Testing with n = 1 gives the right answer. Give a test value that exposes the bug.
Any value except 0 or 1, e.g. n = 5: expected 25, but the program outputs 5 (5 ← 5 × 1)
What are the first and last values of RANGE(1, 11)?
1 and 10 (the end value 11 is not included)
What happens if the loop's arrow goes back to counter ← 0?
An infinite loop: the counter resets every time and never reaches the end