Selection And Iteration Code Guides: Common Logic Errors In Conditional Statements (Copy)
Common Logic Errors In Conditional Statements
Why Logic Errors Are So Costly In Exams
- Logic errors:
- Do not cause syntax errors
- Produce wrong output silently
- Examiners penalise:
- Incorrect conditions
- Impossible conditions
- Conditions that are always TRUE or always FALSE
- Most logic errors occur in:
- IF statements
- Loop conditions
- Combined selection + iteration
Core Examiner Rule
- A condition must be:
- Logically correct
- Reachable
- Meaningful
- Dependent on changing variables
Error Category 1: Using = Instead Of Comparison Logic
The Mistake
- Confusing assignment logic with comparison intent
IF x = 5 THEN
- In pseudocode, this is acceptable as comparison
- But students often:
- Misinterpret what the condition is checking
- Assume it “sets” x to 5 (wrong mental model)
Real Logic Error
x ← 3
IF x = 5 THEN
OUTPUT "Yes"
ENDIF
- Condition is FALSE
- IF body never runs
Examiner Expectation
- You must mentally evaluate the condition
- Do not assume assignment happens in IF
Error Category 2: Impossible Conditions (Always FALSE)
The Mistake
IF num < 0 AND num > 100 THEN
- Why impossible
- A number cannot be less than 0 and greater than 100 at the same time
Correct Logic (Depending On Intent)
- To detect invalid input:
IF num < 0 OR num > 100 THEN
Examiner View
- Impossible conditions = dead code
- Treated as logical misunderstanding
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 AS Level Computer Science Full Scale Course
Error Category 3: Conditions That Are Always TRUE
The Mistake
IF num >= 0 OR num <= 100 THEN
- Why always TRUE
- Every number satisfies at least one side
Correct Version
IF num >= 0 AND num <= 100 THEN
Exam Tip
- Read condition in English:
- “Number is between 0 and 100 inclusive”
- Requires AND, not OR
Error Category 4: Reversed Logic (Opposite Meaning)
The Mistake
IF age > 18 THEN
OUTPUT "Child"
ENDIF
- Logical meaning reversed
Why It Happens
- Rushing
- Not translating condition into English
Safe Fix Method
- Always say condition aloud:
- “If age greater than 18, then… adult”
Error Category 5: Incorrect ELSE / ELSEIF Ordering
The Mistake
IF mark >= 50 THEN
OUTPUT "Pass"
ELSEIF mark >= 80 THEN
OUTPUT "A"
ENDIF
- Why wrong
mark >= 80is never reached- First condition already catches it
Correct Ordering
IF mark >= 80 THEN
OUTPUT "A"
ELSEIF mark >= 50 THEN
OUTPUT "Pass"
ENDIF
Examiner Expectation
- Conditions ordered most specific → least specific
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 AS Level Computer Science Full Scale Course
Error Category 6: Missing ELSE Path (Incomplete Logic)
The Mistake
IF num > 0 THEN
total ← total + num
ENDIF
- Problem
- What happens if
num <= 0? - Sometimes logic requires explicit handling
- What happens if
When Missing ELSE Is Acceptable
- When doing optional processing only
When It Loses Marks
- When:
- Every case must be handled
- Question implies two outcomes
Error Category 7: Updating The Wrong Variable
The Mistake
IF found = FALSE THEN
count ← count + 1
ENDIF
- Intended:
- Change
found
- Change
- Actual:
foundnever changes- Loop may become infinite
Correct Logic
IF arr[index] = target THEN
found ← TRUE
ENDIF
Error Category 8: Condition Variable Never Changes
The Mistake
IF choice = "Y" THEN
OUTPUT "Yes"
ENDIF
- Inside a loop, but:
choiceis never updated
Result
- IF behaves the same every iteration
- Loop logic becomes meaningless
Fix
- Update condition variable inside loop
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 AS Level Computer Science Full Scale Course
Error Category 9: Confusing AND / OR In Multi-Part Conditions
Common Student Error
IF score >= 50 OR score <= 100 THEN
Correct Logic For “Between”
IF score >= 50 AND score <= 100 THEN
OR Is Correct When
- Any one condition is enough
IF choice = "Y" OR choice = "y" THEN
Error Category 10: Using Equality Instead Of Range Logic
The Mistake
IF age = 18 THEN
OUTPUT "Adult"
ENDIF
- What about 19, 20, 25?
Correct Logic
IF age >= 18 THEN
OUTPUT "Adult"
ENDIF
Error Category 11: Selection Placed Outside Iteration
The Mistake
FOR i ← 1 TO 10
INPUT num
NEXT i
IF num > 0 THEN
count ← count + 1
ENDIF
- Only last input checked
Correct Placement
FOR i ← 1 TO 10
INPUT num
IF num > 0 THEN
count ← count + 1
ENDIF
NEXT i
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 AS Level Computer Science Full Scale Course
Error Category 12: Logic That Causes Infinite Loops
Example
WHILE num > 0 DO
IF num > 10 THEN
OUTPUT num
ENDIF
ENDWHILE
- Why infinite
numnever changes
Fix
num ← num - 1
- Every condition variable must be updated
High-Frequency Exam Traps (Quick Table)
| Error | Result |
|---|---|
| Impossible condition | IF never runs |
| Always TRUE condition | IF always runs |
| Wrong AND / OR | Validation fails |
| Bad ELSEIF order | Wrong category |
| Missing update | Infinite loop |
| IF outside loop | Partial logic |
Dry-Run Method To Catch Logic Errors
- Write values of all condition variables
- Evaluate condition manually
- Ask:
- Can this ever be TRUE?
- Can this ever be FALSE?
- If answer is “no” → logic error
Safe Condition-Writing Checklist
- Translate condition into English
- Check AND / OR meaning
- Ensure ranges are correct
- Order ELSEIF correctly
- Ensure condition variable changes
- Ensure all required cases handled
Mini Exam Practice: Identify The Error
Practice 1
IF temp < 0 AND temp > 100 THEN
- Error: impossible condition
Practice 2
IF mark >= 40 THEN
OUTPUT "Pass"
ELSEIF mark >= 70 THEN
OUTPUT "A"
ENDIF
- Error: ELSEIF unreachable
Practice 3
IF num >= 0 OR num <= 10 THEN
- Error: always TRUE
Practice 4
WHILE choice = "Y" DO
OUTPUT "Continue"
ENDWHILE
- Error:
choicenever updated
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 AS Level Computer Science Full Scale Course
One-Line Rules To Memorise
- Read conditions in English
- AND narrows, OR widens
- Order ELSEIF from strict to loose
- Every condition variable must change
- If it can’t ever flip, it’s wrong
