0% found this document useful (0 votes)
11 views10 pages

Computing

The document provides an overview of key programming concepts including algorithms, sequence, selection, and iteration, tailored for Year 9 Cambridge Lower Secondary Computing. It includes definitions, examples, and practice questions to reinforce understanding of these concepts. Additionally, it offers tips for avoiding common pitfalls and a glossary of terms related to computing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Computing

The document provides an overview of key programming concepts including algorithms, sequence, selection, and iteration, tailored for Year 9 Cambridge Lower Secondary Computing. It includes definitions, examples, and practice questions to reinforce understanding of these concepts. Additionally, it offers tips for avoiding common pitfalls and a glossary of terms related to computing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Notes on Sequence, Selection, and Iteration

Year 9 Cambridge Lower Secondary Computing

Author: Mr. Celestino


Date: 06 August 2025

Page 2: Table of Contents

Table of Contents

1. Introduction to Algorithms
2. Sequence
- Example
- Practice Questions
3. Selection
- Examples
- Practice Questions
4. Iteration
- Examples
- Practice Questions
5. Combined Example
- Example
- Practice Questions
6. Tips & Common Pi alls
7. Additional Practice Questions
8. Glossary

Page 3: Introduction

1. Introduction to Algorithms

An algorithm is a clear, step-by-step plan for solving a problem or pe orming a task.

Algorithms can be represented as pseudocode or owcha s. Pseudocode uses


plain-language instructions that resemble code, while owcha s use boxes (steps) and
diamonds (decisions).

Key bene ts of using algorithms early include:


- Breaking complex tasks into manageable steps
- Making debugging easier by tracing each step
- Providing a blueprint before writing actual code

Page 4: Sequence

2. Sequence

Sequence is the simplest control structure. Statements execute one a er another in the
order they appear.

In owcha s, each instruction is shown in a rectangle.

Example
`
SET a TO 4
SET b TO 7
SET sum TO a + b
OUTPUT sum
`

Key points:
- Order ma ers; swapping lines changes results.
- No skipping; each line runs exactly once.
- Ideal for simple calculations, initialization, and I/O.

Page 5: Sequence Practice

Practice Questions for Sequence

1. Perimeter of a Rectangle
Write pseudocode to calculate the perimeter of a rectangle given length and width.

Example Solution:
`
INPUT length
INPUT width
SET perimeter TO 2 * (length + width)
OUTPUT perimeter
`
2. Multiply Three Numbers
Conve the sequence that adds three numbers into a version that multiplies them instead.

Example Solution:
`
SET product TO a b c
OUTPUT product
`

3. Trace Total Calculation


Trace the following pseudocode by listing the value of total a er each step:
`
SET total TO 2
SET x TO 5
SET total TO total + x
SET y TO 4
SET total TO total + y
`

Example Trace:
- A er SET total TO 2 → total = 2
- A er SET x TO 5 → total = 2
- A er SET total TO total + x → total = 7
- A er SET y TO 4 → total = 7
- A er SET total TO total + y → total = 11

Page 6: Selection

3. Selection

Selection lets an algorithm choose di erent paths based on a condition. In owcha s, a


decision point is shown as a diamond.

3.1 Single-Way Selection (IF)


Executes only when a condition is true.
`
IF temperature > 30 THEN
OUTPUT "It’s hot today"
END IF
`
3.2 Two-Way Selection (IF…ELSE)
Choose between two blocks.
`
IF score ≥ 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
END IF
`

3.3 Multi-Way Selection (IF…ELSE IF…ELSE)


Handles multiple conditions in order.
`
IF grade = "A" THEN
OUTPUT "Excellent"
ELSE IF grade = "B" THEN
OUTPUT "Good"
ELSE
OUTPUT "Needs improvement"
END IF
`

Page 7: Selection Practice

Practice Questions for Selection

1. Positive or Negative Check


Write pseudocode that checks if a number is positive. If it is, output “Positive”; otherwise
output “Zero or Negative.”

Example Solution:
`
INPUT num
IF num > 0 THEN
OUTPUT "Positive"
ELSE
OUTPUT "Zero or Negative"
END IF
`
2. Temperature Categorization
Extend the two-way selection to a three-way one: check if a temperature is “cold” (≤ 10),
“warm” (11–25), or “hot” (> 25).

Example Solution:
`
INPUT temp
IF temp ≤ 10 THEN
OUTPUT "Cold"
ELSE IF temp ≤ 25 THEN
OUTPUT "Warm"
ELSE
OUTPUT "Hot"
END IF
`

3. Medal Assignment
Create a multi-way selection to assign medals based on a rank:
1 → “Gold”
2 → “Silver”
3 → “Bronze”
otherwise → “No medal.”

Example Solution:
`
INPUT rank
IF rank = 1 THEN
OUTPUT "Gold"
ELSE IF rank = 2 THEN
OUTPUT "Silver"
ELSE IF rank = 3 THEN
OUTPUT "Bronze"
ELSE
OUTPUT "No medal"
END IF
`

Page 8: Iteration

4. Iteration
Iteration repeats steps until a condition is met or a set count nishes. In owcha s, loops are
shown by arrows that return to earlier steps.

4.1 Count-Controlled Loop (FOR)


Used when you know how many times to repeat.
`
FOR i FROM 1 TO 5
OUTPUT i
END FOR
`

4.2 Condition-Controlled Loop (WHILE)


Runs as long as a condition remains true.
`
SET count TO 0
WHILE count < 3
OUTPUT "Looping"
INCREMENT count
END WHILE
`
Page 9: Iteration Practice

Practice Questions for Iteration

1. Multiples of 3
Write a FOR loop in pseudocode to print the rst ten multiples of 3.

Example Solution:
`
FOR i FROM 1 TO 10
OUTPUT 3 * i
END FOR
`

2. Halving Loop
Use a WHILE loop to keep halving a number until it is less than 1.

Example Solution:
`
INPUT n
WHILE n ≥ 1
OUTPUT n
SET n TO n / 2
END WHILE
`

3. Conve FOR to WHILE


Conve the FOR loop that prints numbers 1–5 into a WHILE loop doing the same task.

Example Solution:
`
SET i TO 1
WHILE i ≤ 5
OUTPUT i
INCREMENT i
END WHILE
`

Page 10: Combined Example

5. Combined Example

Problem: Ask the user for ve numbers and compute their total.

Pseudocode with explanations:


`
SET sum TO 0 // initialize accumulator
FOR i FROM 1 TO 5 // repeat exactly 5 times
INPUT num // get a number from the user
SET sum TO sum + num // add it to the running total
END FOR
OUTPUT "Total =", sum // show nal result
`

Flowcha Steps:
1. Sta
2. Initialise sum and counter i = 1
3. Input number
4. Add to sum
5. Increment i
6. If i ≤ 5, loop back to step 3
7. Output result
8. End

Page 11: Combined Practice

Practice Questions for Combined Example

1. Compute Average
Modify the pseudocode to compute the average of the ve numbers instead of the total.

Example Solution:
`
SET sum TO 0
FOR i FROM 1 TO 5
INPUT num
SET sum TO sum + num
END FOR
SET average TO sum / 5
OUTPUT "Average =", average
`

2. Early Exit on Negative


Change the loop so it stops early if the user enters a negative number.

Example Solution:
`
SET sum TO 0
FOR i FROM 1 TO 5
INPUT num
IF num < 0 THEN
BREAK
END IF
SET sum TO sum + num
END FOR
OUTPUT "Total =", sum
`

3. Flowcha for Average


Draw a owcha for the modi ed version that calculates the average, including the early
exit condition.

Page 12: Tips & Pi alls


6. Tips & Common Pi alls

Sequence:
Watch for using a variable before it’s initialized.

Selection:
- A missing ELSE can leave cases unhandled.
- Overlapping conditions may prevent some branches from ever running.

Iteration:
- Ensure loops have correct exit conditions to avoid in nite loops.
- Check loop bounds to prevent o -by-one errors.

Debugging Strategies:
Trace variable values with print/log statements. Walk through pseudocode step by step using
simple inputs.

Page 13: Additional Practice

7. Additional Practice Questions

1. Unit Conversion
Write pseudocode to conve centimetres → metres → kilometres in sequence.

2. Leap Year Checker


Draw a owcha and write pseudocode to check if a year is a leap year (divisible by 4 but
not by 100, unless also by 400).

3. Even Numbers Loop


Create a loop that prints all even numbers from 2 to 20.

4. Grade Assignment
Develop a program using selection to assign grades A–F from marks 0–100.

5. Count Above 50
Combine loops and selection to count how many of ve inputs are above 50.

Page 14: Glossary

8. Glossary
Algorithm
A precise set of steps to solve a problem.

Sequence
Execution of instructions one a er another.

Selection
Branching based on conditions.

Iteration
Repeating steps until a condition changes.

Pseudocode
Plain-language description of an algorithm.

Flowcha
Diagram showing the ow and decision points of an algorithm.

You might also like