Pseudocode: Writing Algorithm Steps in English
Master the art of writing clear, structured algorithms before coding - essential for CSEC IT success!
What is Pseudocode? (The "False" Code)
Definition
A language-independent way of representing an algorithm using structured English. It's like writing instructions that both humans and computers can understand.
The Goal
To focus on the logic of the solution rather than the punctuation (commas, semicolons, etc.) of a programming language.
Pseudocode vs. Pure English
Why "Add the numbers" is too vague, while "Sum ← Num1 + Num2" is structured and precise.
Drag the slider to transform plain English into structured Pseudocode!
Plain English:
"First, ask the user to type in two numbers. Then add those numbers together. Finally, show the result on the screen."
Pseudocode:
Move the slider to see the transformation...
The Essential Keywords
Input/Output Keywords
- READ, GET, PROMPT - For getting input from the user
- PRINT, DISPLAY, OUTPUT - For showing results
Processing Keywords
- COMPUTE, CALCULATE, SET - For calculations and assignments
- INCREMENT, DECREMENT - For changing values
The Assignment Operator
Using the arrow (←) or equal sign (=) to store values in variables:
Average = Sum / Count
Drag the correct Pseudocode keyword to match each action!
Representing Control Structures
Sequence
Listing steps in logical order (1, 2, 3...). The simplest structure.
Selection (If-Then-Else)
PRINT "Pass"
ELSE
PRINT "Fail"
ENDIF
Iteration (Loops)
FOR Counter ← 1 TO 10
PRINT Counter
ENDFOR
// Condition-controlled loop
WHILE Counter <= 10
PRINT Counter
Counter ← Counter + 1
ENDWHILE
Click a condition (True or False) to see the path the computer takes through the code!
Best Practices for CSEC Pseudocode
Indentation
"Pushing in" lines inside IF or LOOP structures makes code readable for examiners. It shows the structure visually.
Naming Consistency
Ensure variable names in your Pseudocode match your IPO chart. Use meaningful names like "TotalPrice" not "X".
End Statements
Always use ENDIF, ENDFOR, and ENDWHILE to "close the box" of your control structures.
Click the lines that should be indented to make the structure clear!
Flat (Poor) Pseudocode:
From Flowchart to Pseudocode
Mapping Symbols to Syntax
- Parallelogram (I/O) → READ / PRINT
- Rectangle (Process) → SET / CALCULATE
- Diamond (Decision) → IF-THEN-ELSE
- Oval (Start/End) → START / STOP
Click a flowchart symbol to see the corresponding Pseudocode!
Pseudocode Equivalent:
PRINT "Large total"
ENDIF
CSEC SBA Prep: Writing Your Algorithm
Step-by-Step Example
Walkthrough of writing pseudocode for a common SBA task: calculating total cost with discount and tax.
Task: Write pseudocode to calculate the final price of an item after applying a discount and sales tax.
START
READ OriginalPrice, DiscountPercent, TaxRate
DiscountAmount ← OriginalPrice * (DiscountPercent / 100)
PriceAfterDiscount ← OriginalPrice - DiscountAmount
TaxAmount ← PriceAfterDiscount * (TaxRate / 100)
FinalPrice ← PriceAfterDiscount + TaxAmount
PRINT "Original Price: $", OriginalPrice
PRINT "Discount: $", DiscountAmount
PRINT "Final Price: $", FinalPrice
STOP
The Trace Table Link
Your pseudocode must be clear enough for you to test it with a Trace Table later. Each line should represent one logical step.
Knowledge Check: The Pseudocode Editor
Find and click the 3 errors in this pseudocode!
Short Answer
"Why is it better to write pseudocode before typing code into a programming compiler?"
Pseudocode Syntax Guide
Comparison of common CSEC pseudocode keywords with their equivalents in Pascal programming language.
| Purpose | Pseudocode Keyword | Pascal Equivalent |
|---|---|---|
| Input from user | READ, GET | readln(variable); |
| Output to screen | PRINT, DISPLAY | writeln('text'); |
| Assignment | ← or = | variable := value; |
| Condition (if) | IF condition THEN | if condition then |
| Loop (count) | FOR variable ← start TO end | for variable := start to end do |
| Loop (condition) | WHILE condition | while condition do |
| End if statement | ENDIF | end; |
| End loop | ENDFOR, ENDWHILE | end; |
Key Takeaway: Pseudocode focuses on logic, Pascal focuses on syntax. Write pseudocode first, then translate to Pascal!
