Pseudocode Core Structures (Cambridge Standard): Procedure Definition, Calls And Parameter Passing (Copy)
Procedure Definition, Calls And Parameter Passing (Cambridge Standard – O Level 2210 + IGCSE 0478)
Purpose Of Procedures In Cambridge Pseudocode
- Procedures are used to:
- Break large algorithms into smaller logical parts
- Avoid repetition of code
- Improve clarity and structure
- Cambridge assesses procedures to test:
- Modular thinking
- Correct parameter usage
- Understanding of scope and data flow
- Procedures are not about programming language features
- They are about logical decomposition
What Cambridge Means By A Procedure
- A procedure is:
- A named block of pseudocode
- That performs a specific task
- And may receive data through parameters
- Procedures:
- Do not return values directly
- Perform actions (processing, output, updating variables)
Core Procedure Definition Structure (Cambridge Standard)
- PROCEDURE procedureName(parameterList)
- statements
- ENDPROCEDURE
Key Rules
- PROCEDURE keyword must be used
- procedureName:
- Must be meaningful
- Should reflect the task performed
- ENDPROCEDURE:
- Is mandatory
- Missing it causes mark loss
Example Procedure Definition
- PROCEDURE calculateTotal(scoreArray, size)
- total ← 0
- FOR i ← 1 TO size
- total ← total + scoreArray[i]
- ENDFOR
- OUTPUT total
- ENDPROCEDURE
Where Procedures Are Defined
- Procedures are usually defined:
- Before the main program
- Order matters for clarity:
- Define first
- Call later
- Cambridge accepts:
- Procedures written anywhere
- Best practice:
- Procedures at the top
Procedure Calls (How Procedures Are Used)
Standard Procedure Call Structure
- procedureName(argumentList)
Example Procedure Call
- calculateTotal(scores, count)
Examiner Expectations
- Procedure call must:
- Match the procedure name exactly
- Match number of parameters
- Arguments passed:
- Must be valid variables or values
Common Call Errors
- Wrong number of arguments
- Mismatched argument order
- Calling procedure before defining parameters clearly
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
Parameters In Procedures (Core Concept)
What Parameters Are
- Parameters are:
- Variables listed in the procedure definition
- Used to receive data from the calling program
- They act as:
- Placeholders for actual values
Parameter Declaration Style
- PROCEDURE displayResult(name, score)
- OUTPUT name, score
- ENDPROCEDURE
- Data types:
- Usually implied
- Explicit types not required
Formal Parameters Vs Actual Parameters
| Term | Meaning |
|---|---|
| Formal parameter | Variable in procedure definition |
| Actual parameter | Value or variable passed during call |
Example
Procedure definition:
- PROCEDURE showGrade(mark)
Procedure call:
- showGrade(studentMark)
- mark → formal parameter
- studentMark → actual parameter
Parameter Passing Concept (Cambridge View)
- Cambridge focuses on:
- Logical flow of data
- Not language-specific mechanisms
- For exam purposes:
- Parameters are assumed to be passed by value
- Unless question context implies update of shared data
Pass-By-Value (Exam-Safe Understanding)
- Changes to parameter inside procedure:
- Do NOT affect original variable outside
- Used when:
- Procedure performs calculations
- Outputs results
Example
- PROCEDURE addOne(x)
- x ← x + 1
- ENDPROCEDURE
Main program:
- num ← 5
- addOne(num)
- OUTPUT num
- Output remains:
- 5
When Changes Appear To Persist (Common Confusion)
- If arrays or records are passed:
- Changes appear to persist
- Why:
- Data structure itself is modified
- Cambridge expects students to:
- Understand this conceptually
- Not explain it in technical terms
Example With Array
- PROCEDURE updateScore(scores, index, value)
- scores[index] ← value
- ENDPROCEDURE
- updateScore(scoreArray, 3, 90)
- scoreArray[3] is updated after call
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
Procedures And Variable Scope (Cambridge Interpretation)
Local Scope
- Variables declared inside a procedure:
- Are local to that procedure
- They:
- Cannot be accessed outside
Global Scope (Implicit)
- Variables declared in main program:
- Can be passed into procedures
- Procedures should not:
- Rely on undeclared external variables
Examiner Trap
- Using variables inside procedure:
- That were never passed as parameters
- This shows:
- Poor modular understanding
Procedures With No Parameters
- Procedures may:
- Take no parameters
- Used when:
- Procedure performs fixed action
Example:
- PROCEDURE showMenu
- OUTPUT “1. Add”
- OUTPUT “2. Exit”
- ENDPROCEDURE
Call:
- showMenu
Procedures With Multiple Parameters
- Parameter order matters
- Must match in call
Example:
- PROCEDURE calculateAverage(total, count)
Call:
- calculateAverage(sum, number)
- Swapping arguments:
- Produces logical error
Procedures Inside Iteration And Selection
Procedure Calls Inside Loops
- FOR i ← 1 TO n
- processRecord(i)
- ENDFOR
- Procedure called:
- Once per iteration
Procedure Calls Inside IF
- IF option = 1 THEN
- addRecord()
- ENDIF
Examiner Expectations
- Procedure calls:
- Must not hide loop logic
- Loop and selection logic:
- Must remain visible in main program
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
Procedures And Trace Tables
- When tracing:
- Treat procedure body as expanded inline
- Track:
- Parameter values
- Local variable changes
- Do NOT:
- Skip procedure logic in trace
Common Trace Errors
- Forgetting parameter values
- Assuming procedures return values
- Ignoring variable updates inside procedures
Procedures In Section B Modifications
- Section B may ask:
- Write a procedure
- Modify an existing procedure
- Add a procedure call
- Examiner expects:
- Minimal integration
- No rewriting of main algorithm
Safe Modification Strategy
- Add new procedure
- Call it from existing logic
- Do not:
- Merge procedure logic into main program
Common Procedure Mistakes (Guaranteed Mark Loss)
- Missing ENDPROCEDURE
- Mismatch between parameters and arguments
- Using RETURN in a procedure
- Treating procedure like a function
- Using undeclared variables inside procedure
- Wrong parameter order
Procedures Vs Functions (Cambridge Distinction)
| Procedure | Function |
|---|---|
| Performs task | Returns value |
| No RETURN | Has RETURN |
| Often outputs | Used in expressions |
- Do not mix:
- RETURN with PROCEDURE
Best-Practice Procedure Strategy For Paper 2
- Use procedures to:
- Isolate repeated logic
- Improve readability
- Keep procedures:
- Short
- Focused
- Pass all required data as parameters
- Avoid hidden dependencies
Final Quality Checklist
- PROCEDURE and ENDPROCEDURE present
- Meaningful procedure name
- Correct parameter list
- Correct procedure calls
- No return values used
- Variables scoped correctly
Final Lock-In Rules
- Procedures improve structure, not complexity
- Parameters control data flow
- Order and matching of parameters matter
- Procedures do not return values
- Clean procedure logic earns easy Paper 2 marks
