Pseudocode Core Structures (Cambridge Standard): Assignment Statements And Operator Precedence (Copy)
Assignment Statements And Operator Precedence (Cambridge Standard – O Level 2210 + IGCSE 0478)
Purpose Of Assignment Statements In Cambridge Pseudocode
- Assignment statements are used to:
- Store values in variables
- Update values during processing
- Capture results of calculations
- Cambridge pseudocode prioritises:
- Clarity of logic
- Correct sequencing
- Traceable value changes
- Assignment is the backbone of:
- Calculations
- Counters
- Accumulators
- Flags
- Data updates
The Cambridge Assignment Operator
The Only Correct Assignment Symbol
- ← (left arrow)
Examples:
- total ← 0
- count ← count + 1
- average ← total / count
- Meaning:
- The expression on the right-hand side is evaluated first
- The result is stored in the variable on the left-hand side
What Assignment Is NOT
- Assignment is NOT comparison
- Assignment is NOT equality testing
Incorrect:
- total = 0
- count == count + 1
Correct:
- total ← 0
Assignment Evaluation Rule (Examiner-Critical)
- Always evaluate:
- Right-hand side completely
- Then assign to left-hand side
- Example:
- x ← x + 1
- Meaning:
- Take old value of x
- Add 1
- Store result back in x
Common Assignment Mistakes That Lose Marks
- Using = instead of ←
- Reversing assignment direction
- Assigning to constants
- Using uninitialised variables
- Changing variable role mid-algorithm
Assignment And Initialisation
Initialisation Is Mandatory
- Variables must be initialised before use
- Especially important for:
- Accumulators
- Counters
- Flags
Correct:
- total ← 0
- count ← 0
- found ← FALSE
Incorrect:
- total ← total + value (total not initialised)
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
Types Of Assignment Statements
Simple Assignment
- Assigning a literal value
Examples:
- score ← 75
- name ← “Ali”
- valid ← TRUE
Assignment Using Variables
- Assigning value of one variable to another
Examples:
- finalScore ← score
- highest ← current
Assignment Using Expressions
- Assigning result of a calculation
Examples:
- total ← total + score
- average ← total / count
- area ← length * width
Assignment With Array Elements
- Assigning to or from arrays
Examples:
- score[i] ← value
- total ← total + score[i]
Rules:
- Index must be valid
- Array must be declared before use
Assignment With Record Fields
Examples:
- Student.mark ← score
- Student.name ← name
Rules:
- Field names must be consistent
- Record must be declared
Assignment Inside Control Structures
Assignment Inside IF Statements
- IF condition THEN
- total ← total + value
- ENDIF
- Assignment executes only if condition is TRUE
Assignment Inside Loops
- FOR i ← 1 TO 30
- total ← total + score[i]
- ENDFOR
- Loop-based assignments:
- Affect accumulators
- Affect counters
Assignment And Trace Tables
- Every assignment:
- Produces a value change
- Trace tables rely on:
- Correct assignment sequencing
- One wrong assignment:
- Cascades into multiple incorrect trace values
Trace-Safe Assignment Rule
- After every assignment, ask:
- Which variable changed?
- What is its new value?
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
Operator Precedence In Cambridge Pseudocode
Why Operator Precedence Matters
- Operator precedence determines:
- The order in which parts of an expression are evaluated
- Misunderstanding precedence:
- Produces wrong results
- Breaks trace questions
- Loses marks even if logic intention was correct
Cambridge Operator Precedence Order (High To Low)
- Brackets ( )
- Exponentiation (if used)
- Multiplication (*) and Division (/)
- Addition (+) and Subtraction (−)
- Relational operators (<, >, ≤, ≥, =, ≠)
- Logical NOT
- Logical AND
- Logical OR
Basic Numeric Precedence Examples
- result ← 5 + 3 * 2
- result = 11
- result ← (5 + 3) * 2
- result = 16
Why Brackets Are Strongly Recommended
- Even if precedence is correct:
- Brackets improve clarity
- Reduce examiner ambiguity
- Cambridge rewards clarity over cleverness
Relational And Logical Operator Precedence
Relational Operators
Examples:
- score >= 50
- count < max
- Evaluated after arithmetic, before logical operators
Logical Operator Precedence
Order:
- NOT
- AND
- OR
Example:
- IF NOT valid AND count < max THEN
Interpreted as:
- IF (NOT valid) AND (count < max)
Ambiguous Expressions (Avoid These)
- IF a > b AND c > d OR e = f THEN
Better:
- IF (a > b AND c > d) OR (e = f) THEN
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
Assignment Combined With Operator Precedence (High-Risk Area)
Example 1: Accumulator Update
- total ← total + score * weight
Correct interpretation:
- score * weight first
- Then added to total
Example 2: Average Calculation
- average ← total / count + bonus
Interpreted as:
- (total / count) + bonus
If bonus must apply first:
- average ← total / (count + bonus)
Example 3: Conditional Assignment Logic
- IF score + bonus >= passMark THEN
Interpreted as:
- (score + bonus) >= passMark
Common Precedence Mistakes In Exams
- Forgetting brackets
- Assuming left-to-right evaluation
- Mixing arithmetic and logic without grouping
- Misinterpreting AND / OR combinations
Examiner Expectations For Operator Usage
- Expressions must be:
- Logically correct
- Easy to trace
- Overly complex expressions:
- Increase error risk
- Are not rewarded
Best-Practice Rules For Assignment And Precedence
- Always initialise variables
- Use ← for assignment only
- Use brackets generously
- Keep expressions simple
- Split complex expressions into multiple assignments if needed
Example:
- temp ← score * weight
- total ← total + temp
Assignment And Boolean Values
Correct Boolean Assignment
- found ← FALSE
- valid ← TRUE
Boolean Assignment With Expressions
- valid ← score >= 0 AND score <= 100
- Result stored is:
- TRUE or FALSE
Assignment And Data Types
- Assignment must respect data type
- INTEGER assigned from:
- INTEGER expression
- REAL assigned from:
- REAL expression
Example:
- average ← total / count (REAL)
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 Assignment And Precedence
- Using assignment inside conditions incorrectly
- Forgetting that assignment updates variable permanently
- Reusing variables for different purposes
- Writing expressions that cannot be traced cleanly
Final Quality Checklist (Before Moving On)
- All variables are initialised
- All assignments use ←
- Operator precedence is clear
- Brackets used where necessary
- No ambiguous expressions
- All assignments are traceable
Final Lock-In Rules
- Assignment evaluates right to left
- Operator precedence affects correctness
- Brackets remove ambiguity
- Clear assignment logic = higher Paper 2 marks
