Pseudocode Core Structures (Cambridge Standard): Variable Declaration Rules And Data Types In Pseudocode (Copy)
Variable Declaration Rules And Data Types In Pseudocode (Cambridge Standard – O Level 2210 + IGCSE 0478)
Purpose Of Variable Declarations In Cambridge Pseudocode
- Variables are used to:
- Store data temporarily
- Track values during processing
- Control loops and conditions
- Cambridge pseudocode focuses on:
- Logical clarity
- Language independence
- Variable declaration is not about syntax correctness of a language
- It is about clarity of intention
Cambridge’s General Rule On Variable Declaration
- Cambridge pseudocode:
- Does not require strict declaration syntax
- Does require:
- Clear variable purpose
- Consistent usage
- Appropriate data type choice
- Examiners expect:
- Variables to be introduced before use
- Variable names to reflect their role
When Variables Should Be Declared
- Variables should be declared:
- At the start of an algorithm
- Or immediately before first use
- Arrays and records:
- Must be declared before indexing or field access
- Loop counters:
- Must be clearly introduced before or within the loop
Acceptable Cambridge-Style Variable Declaration Formats
Informal Declaration (Most Common)
- total ← 0
- count ← 0
- found ← FALSE
- This is acceptable because:
- The data type is obvious from the value
- The purpose is clear
Explicit Declaration (Also Acceptable)
- DECLARE total : INTEGER
- DECLARE average : REAL
- DECLARE name : STRING
- Used when:
- Data type clarity matters
- Multiple variables are introduced together
Array Declaration (Cambridge-Safe)
- DECLARE score[1:30] : INTEGER
- DECLARE name[1:50] : STRING
- Key points:
- Index range must match pre-release constraints
- Size must not exceed stated limits
Record Declaration (If Used)
- DECLARE Student AS RECORD
- name : STRING
- mark : INTEGER
- id : INTEGER
- END RECORD
- Parallel arrays are also acceptable
- Records are preferred when:
- Data fields logically belong together
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Variable Naming Rules (Cambridge Expectations)
What Makes A Good Variable Name
- Descriptive and meaningful
- Reflects stored data
- Avoids single-letter names unless:
- Loop counters (i, j)
Good vs Bad Examples
| Good Name | Why It’s Good | Bad Name | Why It’s Bad |
|---|---|---|---|
| totalScore | Clear meaning | x | No meaning |
| studentID | Descriptive | temp | Vague |
| isValid | Boolean intent clear | flag1 | Unclear purpose |
Case Sensitivity
- Cambridge pseudocode:
- Is not case-sensitive
- Best practice:
- Use consistent camelCase or underscores
- Be consistent throughout the answer
Core Data Types Used In Cambridge Pseudocode
INTEGER
- Stores whole numbers
- Common uses:
- Counters
- Indexes
- Marks
- IDs
Examples:
- count ← 0
- mark ← 75
REAL
- Stores decimal values
- Used when:
- Fractions are possible
- Averages
- Monetary values
Examples:
- average ← total / count
- price ← 19.99
STRING
- Stores text
- Used for:
- Names
- Codes
- Messages
Examples:
- name ← “Ali”
- message ← “Invalid input”
BOOLEAN
- Stores TRUE or FALSE only
- Used for:
- Flags
- Conditions
- Search success
Examples:
- found ← FALSE
- valid ← TRUE
CHAR (Less Common But Acceptable)
- Stores a single character
- Used for:
- Menu options
- Yes/No input
Examples:
- choice ← ‘Y’
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Choosing The Correct Data Type (Examiner Logic)
Examiner Checks
- Is the data type:
- Suitable for the value?
- Consistent with operations?
- Incorrect data type:
- Causes logic errors
- Loses marks in trace questions
Common Data Type Mistakes
- Using INTEGER for averages
- Using STRING for numeric comparisons
- Using REAL where only whole numbers exist
Data Type Selection Table
| Scenario | Correct Data Type |
|---|---|
| Student marks | INTEGER |
| Average mark | REAL |
| Name | STRING |
| Menu option | INTEGER or CHAR |
| Found/not found | BOOLEAN |
Variable Initialisation Rules
- Variables must be:
- Initialised before use
- Especially important for:
- Counters
- Accumulators
- Flags
Correct Initialisation Examples
- total ← 0
- count ← 0
- found ← FALSE
Common Initialisation Errors
- Forgetting to set initial values
- Initialising inside loop when it should be outside
- Using uninitialised variables in conditions
Arrays And Indexing Rules
Array Indexing (Cambridge Standard)
- Indexing typically starts at:
- 1 (preferred)
- Must remain consistent
Example:
- FOR i ← 1 TO 30
Array Access
- score[i]
- name[i]
- Index must:
- Stay within declared bounds
- Match loop limits
Common Array Mistakes
- Off-by-one errors
- Accessing undeclared indexes
- Loop exceeding array size
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Constants In Cambridge Pseudocode
- Constants may be used to:
- Improve readability
- Avoid magic numbers
Example:
- MAX ← 30
- FOR i ← 1 TO MAX
- Constants:
- Should not change
- Are often declared at the top
Implicit vs Explicit Data Typing
Implicit Typing
- Type inferred from assigned value
- Fully acceptable
Example:
- count ← 0
Explicit Typing
- Type stated using DECLARE
- Useful for clarity in complex answers
Example:
- DECLARE count : INTEGER
Examiner Preference
- Both are accepted
- Clarity > syntax style
Variable Scope (Cambridge Interpretation)
- Cambridge pseudocode assumes:
- Simple global scope unless stated
- Variables declared:
- Outside loops can be used inside
- Loop counters:
- Should not be reused incorrectly
Boolean Logic And Variable Usage
- Boolean variables:
- Should be used directly in conditions
Correct:
- IF found = TRUE THEN
Better:
- IF found THEN
Data Types And Trace Tables
- Correct data types ensure:
- Accurate trace values
- Common trace errors:
- Decimal truncated due to INTEGER assumption
- Boolean misunderstood as string
Trace-Safe Variable Checklist
- Every variable has:
- Clear initial value
- Correct type
- Clear update rules
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Examiner Traps Related To Variables And Data Types
- Using same variable for multiple purposes
- Changing variable role mid-algorithm
- Mismatched data type in comparison
- Forgetting to initialise accumulators
- Using vague variable names
Best-Practice Variable Strategy For Paper 2
- Declare variables early
- Initialise immediately
- Use descriptive names
- Choose simplest suitable data type
- Be consistent
- Avoid unnecessary variables
Final Lock-In Rules
- Cambridge cares about:
- Logic
- Clarity
- Consistency
- Not about:
- Programming language syntax
- Correct variable declaration and data type usage:
- Improves algorithm marks
- Prevents trace errors
- Makes examiner marking easier
