Resources | Subject Notes | Computer Science
This section provides detailed notes and examples on writing pseudo-code from structured English descriptions, a crucial skill for the Cambridge A-Level Computer Science 9618 exam. Pseudo-code is an informal way of representing an algorithm, making it easier to understand and translate into a specific programming language.
Structured English is a simplified form of English that uses keywords to represent control structures like sequencing, selection (if-then-else), and repetition (loops). It provides a clear and concise way to describe the logic of an algorithm.
Common keywords in structured English include:
BEGIN
and END
: Mark the start and end of a block of code.IF
: Starts a conditional statement.THEN
: Follows the condition in an IF
statement.ELSE
: Provides an alternative block of code if the condition is false.WHILE
: Starts a loop that continues as long as a condition is true.REPEAT
: Starts a loop that repeats a block of code a specified number of times.UNTIL
: Starts a loop that continues until a condition becomes true.The process of converting structured English to pseudo-code involves translating the keywords and logical structures into a more formal, algorithm-like format. Here's a general approach:
Structured English:
BEGIN Input the first number. Input the second number. IF the first number is greater than the second number THEN Output the first number as the maximum. ELSE Output the second number as the maximum. ENDIF END
Pseudo-code:
Step | Description |
---|---|
1 | Begin |
2 | Input number1 |
3 | Input number2 |
4 | If number1 > number2 Then |
5 | Output number1 |
6 | Else |
7 | Output number2 |
8 | End If |
9 | End |
Structured English:
BEGIN Input the number of elements in the list. Input each element of the list. Set the sum to zero. FOR each element in the list DO Add the element to the sum. END FOR Output the sum. END
Pseudo-code:
Step | Description |
---|---|
1 | Begin |
2 | Input list_size |
3 | Set sum = 0 |
4 | For i = 1 to list_size do |
5 | Input element[i] |
6 | sum = sum + element[i] |
7 | End For |
8 | Output sum |
9 | End |
Structured English:
BEGIN Input a number. IF the number is greater than zero THEN Output "The number is positive." ELSE Output "The number is not positive." ENDIF END
Pseudo-code:
Step | Description |
---|---|
1 | Begin |
2 | Input number |
3 | If number > 0 Then |
4 | Output "The number is positive." |
5 | Else |
6 | Output "The number is not positive." |
7 | End If |
8 | End |
When writing pseudo-code, it's important to: