Cost And Management Accounting Formats (AS Level): Absorption Costing Profit Statement Format (Copy)
IF, ELSE IF And ELSE Structures Explained
Purpose Of Selection Structures
- Selection allows a program to choose between alternative paths
- Examiner checks:
- Correct condition logic
- Correct structure and block closure
- Clear, traceable decision flow
- IF, ELSE IF and ELSE are used when decisions depend on conditions
Basic IF Structure (Single Decision)
| Use Case | Description |
|---|---|
| One condition | Action taken only if condition is true |
Correct IF Structure
IF Age >= 18 THEN
OUTPUT "Eligible"
ENDIF
- Condition evaluated once
- If FALSE, block is skipped
- ENDIF is mandatory
IF–ELSE Structure (Two Possible Outcomes)
| Use Case | Description |
|---|---|
| Yes / No decision | Exactly one outcome must occur |
Correct IF–ELSE Structure
IF Score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
- One condition
- One true path
- One false path
- Both paths clearly defined
Common IF–ELSE Mistake And Fix
| Mistake | Why Wrong | Correct |
|---|---|---|
| Missing ELSE | No false action | Include ELSE |
| Missing ENDIF | Block unclear | Always close |
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
ELSE IF Structure (Multiple Conditions)
| Use Case | Description |
|---|---|
| Multiple exclusive conditions | Only one condition should execute |
Standard ELSE IF Pattern
IF Score >= 80 THEN
Grade ← 'A'
ELSE IF Score >= 60 THEN
Grade ← 'B'
ELSE IF Score >= 40 THEN
Grade ← 'C'
ELSE
Grade ← 'F'
ENDIF
- Conditions checked top to bottom
- First TRUE condition executes
- Remaining conditions are skipped
ELSE IF Condition Ordering (Critical)
| Order | Why Important |
|---|---|
| Highest first | Prevents incorrect matches |
| Specific before general | Avoids early capture |
Incorrect Ordering
IF Score >= 40 THEN
Grade ← 'C'
ELSE IF Score >= 80 THEN
Grade ← 'A'
ENDIF
- Score = 85 gives Grade C (wrong)
Correct Ordering
IF Score >= 80 THEN
Grade ← 'A'
ELSE IF Score >= 40 THEN
Grade ← 'C'
ENDIF
ELSE IF Vs Nested IF (Exam-Safe Comparison)
| ELSE IF | Nested IF |
|---|---|
| Cleaner | More verbose |
| Easier to trace | Deeper indentation |
| Preferred when exclusive | Used when dependent |
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
Nested IF Structures (Dependent Conditions)
| Use Case | Description |
|---|---|
| Condition depends on another | Second check only if first true |
Nested IF Example
IF Age >= 18 THEN
IF HasID = TRUE THEN
OUTPUT "Entry Allowed"
ELSE
OUTPUT "ID Required"
ENDIF
ELSE
OUTPUT "Underage"
ENDIF
- Second IF only evaluated if first IF is TRUE
- Useful for hierarchical logic
ELSE IF Vs Nested IF (When To Choose)
| Situation | Best Choice |
|---|---|
| Independent conditions | ELSE IF |
| Dependent checks | Nested IF |
| Grading systems | ELSE IF |
| Access control | Nested IF |
Using Boolean Conditions Clearly
IF Found = TRUE THEN
OUTPUT "Value Found"
ELSE
OUTPUT "Not Found"
ENDIF
- Always compare BOOLEAN explicitly
- Avoid ambiguous conditions
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
Selection With Compound Conditions
| Operator | Meaning |
|---|---|
| AND | Both conditions true |
| OR | At least one true |
| NOT | Reverse condition |
Compound Condition Example
IF (Age >= 18) AND (HasID = TRUE) THEN
OUTPUT "Allowed"
ELSE
OUTPUT "Denied"
ENDIF
- Brackets improve readability
- Prevents logic misinterpretation
Assignment Inside Selection (Clean Logic Pattern)
IF Score >= 50 THEN
Result ← "Pass"
ELSE
Result ← "Fail"
ENDIF
OUTPUT Result
- Decision and output separated
- Easier marking and tracing
IF Inside Loops (Very Common Exam Pattern)
FOR i ← 1 TO 5
IF Marks[i] >= 50 THEN
PassCount ← PassCount + 1
ENDIF
ENDFOR
- IF controls action per iteration
- Loop logic remains clean
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
ELSE IF With Validation Logic
REPEAT
INPUT Choice
IF Choice < 1 THEN
OUTPUT "Too low"
ELSE IF Choice > 3 THEN
OUTPUT "Too high"
ENDIF
UNTIL Choice >= 1 AND Choice <= 3
- Multiple validation messages
- Controlled exit condition
Common Examiner Mistakes And Fixes
| Mistake | Why Marks Lost | Fix |
|---|---|---|
| Wrong condition order | Incorrect result | Highest first |
| Missing ELSE | No false path | Add ELSE |
| Missing ENDIF | Broken structure | Always close |
| Over-nesting | Hard to trace | Use ELSE IF |
| Assignment in IF | Logic error | Use comparison |
Examiner-Safe Selection Template
IF condition THEN
statements
ELSE IF condition THEN
statements
ELSE
statements
ENDIF
- Clean
- Predictable
- Examiner-friendly
