Nested Conditions and Complex Decision Making | CSEC IT

Nested Conditions and Complex Decision Making

Master multi-level decision logic - essential for CSEC IT algorithm design!

🎯 Learning Objectives

Explain what nested conditions are

Write nested IF and IF-ELSE statements using CSEC-style pseudocode

Use logical operators to create complex conditions

Interpret and trace algorithms with multiple decision paths

Answer CSEC exam questions involving complex decision-making

1

Introduction to Nested Conditions

Nested conditions are decision structures placed inside other decision structures. They allow programs to make complex, multi-level decisions - like a decision tree where each choice leads to more choices.

Real-Life Nested Decisions

Think about getting a driver's license in the Caribbean:

Age ≥ 17?
YES
Passed written test?
NO
"Too young"
YES
Passed road test?
NO
"Study more"
YES
"License approved"
NO
"Practice driving"

Each "YES" or "NO" leads to another decision - this is nesting in action!

💡 Why Simple IF-ELSE Isn't Enough

Single IF-ELSE statements work for binary choices (yes/no, true/false). But real-world decisions often have multiple levels:

  • Grading systems (A, B, C, D, F with plus/minus variations)
  • Eligibility rules (age AND residency AND qualifications)
  • Discount systems (member status AND purchase amount AND season)

For these, we need nested conditions or compound logical operators.

2

What Are Nested IF Statements?

Definition

A nested IF statement is an IF statement placed inside another IF statement. The inner IF only gets evaluated if the outer IF's condition is TRUE (or FALSE, depending on placement).

Basic Structure

// Outer IF statement
IF outer_condition THEN
// Inner IF statement (nested)
IF inner_condition THEN
// Code to execute if BOTH conditions are TRUE
ENDIF
ENDIF

Simple Example: Scholarship Eligibility

// Caribbean scholarship system
INPUT gpa, extracurricular
IF gpa ≥ 3.5 THEN
// Only check extracurricular if GPA is high enough
IF extracurricular = "Excellent" THEN
DISPLAY "Eligible for President's Scholarship"
ENDIF
ENDIF
DISPLAY "Application review complete"

Execution Paths:

  • Path 1: GPA = 3.8, extracurricular = "Excellent" → Display scholarship message
  • Path 2: GPA = 3.8, extracurricular = "Good" → No scholarship message
  • Path 3: GPA = 3.2 → Skip inner IF completely

🧠 Think About It

What's the difference between these two structures?

// Structure A: Nested IF
IF condition1 THEN
IF condition2 THEN
action
ENDIF
ENDIF

// Structure B: Combined with AND
IF condition1 AND condition2 THEN
action
ENDIF

Answer: They are logically equivalent! Both execute the action only if BOTH conditions are TRUE. However, Structure A (nested) allows for additional code between the outer and inner IF, while Structure B (AND) is cleaner for simple combined conditions.

3

Building Complex Conditions Using Logical Operators

Logical Operator Review

AND

Logical AND

TRUE only if BOTH conditions are TRUE

Example: age ≥ 18 AND hasID = TRUE
OR

Logical OR

TRUE if AT LEAST ONE condition is TRUE

Example: grade = "A" OR grade = "B"
NOT

Logical NOT

Reverses the truth value

Example: NOT (score < 50)

Reducing Nesting with Logical Operators

Often, nested IF statements can be simplified using AND, OR, and NOT:

// Nested version (3 levels deep)
IF age ≥ 18 THEN
IF citizen = TRUE THEN
IF registered = TRUE THEN
DISPLAY "Can vote"
ENDIF
ENDIF
ENDIF

// Simplified with AND operator
IF age ≥ 18 AND citizen = TRUE AND registered = TRUE THEN
DISPLAY "Can vote"
ENDIF

CSEC-Style Examples with Caribbean Context

// Example 1: Hurricane preparedness level
INPUT windSpeed, rainfall, stormSurge
IF windSpeed > 155 OR rainfall > 20 OR stormSurge > 18 THEN
DISPLAY "EXTREME DANGER - EVACUATE IMMEDIATELY"
ELSE IF (windSpeed ≥ 131 AND windSpeed ≤ 155) OR rainfall > 15 THEN
DISPLAY "MAJOR THREAT - PREPARE TO EVACUATE"
ELSE
DISPLAY "MONITOR CONDITIONS"
ENDIF
// Example 2: Caribbean festival competition eligibility
INPUT age, costumeScore, performanceScore, residency
IF age ≥ 16 AND age ≤ 35 AND residency = "Caribbean" THEN
IF costumeScore ≥ 8 OR performanceScore ≥ 9 THEN
DISPLAY "Qualified for finals"
ELSE
DISPLAY "Did not qualify - scores too low"
ENDIF
ELSE
DISPLAY "Not eligible - age or residency requirement not met"
ENDIF

⚠️ Operator Precedence Matters!

In complex conditions, AND is evaluated before OR unless you use parentheses. This can lead to logic errors:

// Problematic without parentheses
IF age ≥ 18 AND citizen = TRUE OR specialPermission = TRUE THEN
// This means: (age ≥ 18 AND citizen = TRUE) OR specialPermission = TRUE
// Might not be what you intended!

// Clear with parentheses
IF (age ≥ 18 AND citizen = TRUE) OR specialPermission = TRUE THEN
// Intent is clear

CSEC Tip: Use parentheses to make your logic clear to examiners, even if they're not strictly necessary.

4

Nested IF-THEN Structures (CSEC-Style)

Standard CSEC Format

In CSEC exams, proper indentation is crucial for readability. Each level of nesting should be indented consistently.

// Standard format for nested IF-THEN
IF outer_condition THEN
// Level 1 indentation
IF inner_condition THEN
// Level 2 indentation
action
ENDIF
ENDIF

Worked Example 1: Academic Honors System

// Caribbean secondary school honors
INPUT gpa, attendance
IF gpa ≥ 3.8 THEN
// Only check attendance if GPA is high enough
IF attendance ≥ 95 THEN
DISPLAY "Principal's Honor Roll"
ENDIF
ENDIF
DISPLAY "Honors review completed"

Execution Path Visualization (gpa = 3.9, attendance = 96):

Start
gpa ≥ 3.8? ✓
attendance ≥ 95? ✓
Display Honors
Complete

Worked Example 2: Cricket Match Ticket Pricing

// Caribbean Premier League ticket system
INPUT age, memberStatus, matchType
SET price = 100 // Base price in USD
IF age < 12 THEN
// Child discount
SET price = price * 0.5 // 50% discount
IF memberStatus = "Family" THEN
// Additional family member discount
SET price = price * 0.9 // Extra 10% off
ENDIF
ENDIF
IF matchType = "Final" THEN
// Premium for finals
SET price = price * 1.5
ENDIF
DISPLAY "Final ticket price: $", price
Predict the Output

What price will be displayed for: age = 10, memberStatus = "Family", matchType = "Final"?

Base: $100
Child: $50
Family: $45
Final: $67.50

Calculation:
1. Base price: $100
2. Child discount (50%): $100 × 0.5 = $50
3. Family discount (extra 10%): $50 × 0.9 = $45
4. Final match premium (50% increase): $45 × 1.5 = $67.50
Output: "Final ticket price: $67.50"

📝 CSEC Exam Format

In CSEC exams, nested conditions often appear in:

  • Trace tables - showing execution paths through nested logic
  • Pseudocode completion - filling in missing conditions or actions
  • Algorithm design - creating multi-level decision systems
  • Error detection - finding missing ENDIF statements or incorrect nesting

Key skill: Proper indentation makes your logic clear to examiners.

5

Nested IF-THEN-ELSE Structures

Multi-Level Decision Trees

When decisions have multiple levels with different outcomes at each level, we use nested IF-THEN-ELSE structures.

Caribbean Grading System Example

// CSEC-style grading with plus/minus variations
INPUT score
IF score ≥ 90 THEN
// A range
IF score ≥ 97 THEN
DISPLAY "A+"
ELSE IF score ≥ 93 THEN
DISPLAY "A"
ELSE
DISPLAY "A-"
ENDIF
ELSE IF score ≥ 80 THEN
// B range
IF score ≥ 87 THEN
DISPLAY "B+"
ELSE IF score ≥ 83 THEN
DISPLAY "B"
ELSE
DISPLAY "B-"
ENDIF
ELSE
// C or below
IF score ≥ 70 THEN
DISPLAY "C"
ELSE
DISPLAY "F - Needs improvement"
ENDIF
ENDIF

Decision Tree Representation (score = 85):

score ≥ 90?
YES
A range check
NO
score ≥ 80?
YES
B range check
NO
C or F check
score ≥ 87? YES
B+

Another Example: Caribbean Travel Advisory System

// Multi-level travel advisory
INPUT hurricaneCategory, rainfallWarning, coastalWarning
IF hurricaneCategory ≥ 4 THEN
DISPLAY "LEVEL 4: AVOID ALL TRAVEL"
ELSE IF hurricaneCategory = 3 THEN
IF rainfallWarning = "Severe" OR coastalWarning = "Severe" THEN
DISPLAY "LEVEL 3: ESSENTIAL TRAVEL ONLY"
ELSE
DISPLAY "LEVEL 2: HIGH CAUTION"
ENDIF
ELSE IF hurricaneCategory = 2 THEN
IF rainfallWarning = "Moderate" AND coastalWarning = "Moderate" THEN
DISPLAY "LEVEL 2: HIGH CAUTION"
ELSE
DISPLAY "LEVEL 1: EXERCISE CAUTION"
ENDIF
ELSE
DISPLAY "LEVEL 0: NORMAL TRAVEL"
ENDIF

🔍 Trace the Path

Follow this algorithm with: score = 76

INPUT score
IF score ≥ 80 THEN
IF score ≥ 90 THEN
DISPLAY "A"
ELSE
DISPLAY "B"
ENDIF
ELSE
IF score ≥ 70 THEN
DISPLAY "C"
ELSE IF score ≥ 60 THEN
DISPLAY "D"
ELSE
DISPLAY "F"
ENDIF
ENDIF

Trace:
1. score ≥ 80? 76 ≥ 80? FALSE → Go to ELSE
2. score ≥ 70? 76 ≥ 70? TRUE → Display "C"
3. Skip remaining ELSE IF and ELSE
4. Output: "C"

6

Flowchart Representation of Nested Decisions

Multiple Decision Diamonds

In flowcharts, each decision point uses a diamond shape. Nested decisions create multiple diamonds with branching paths.

START
INPUT age
age ≥ 18?
YES
NO
INPUT license
license = "Valid"?
DISPLAY "Too young"
YES
NO
DISPLAY "Can drive"
DISPLAY "Need license"
END

Corresponding Pseudocode

INPUT age
IF age ≥ 18 THEN
INPUT license
IF license = "Valid" THEN
DISPLAY "Can drive"
ELSE
DISPLAY "Need license"
ENDIF
ELSE
DISPLAY "Too young"
ENDIF

Complex Flowchart Tips for CSEC Exams

  • Label all branches clearly (YES/NO or TRUE/FALSE)
  • Use consistent spacing to show nesting levels
  • Connect all paths to avoid dangling branches
  • Merge paths when multiple branches lead to the same outcome
  • Check flow direction with arrows on all connectors

💡 Flowchart to Pseudocode Conversion

When converting flowcharts to pseudocode in CSEC exams:

  1. Identify the outermost decision (first diamond)
  2. Write the IF statement for that condition
  3. Work inward through nested decisions
  4. Add ENDIF for each IF statement
  5. Check that your indentation matches the flowchart structure
7

Tracing Nested Conditions

Step-by-Step Tracing Methodology

Tracing nested conditions requires careful attention to evaluation order and indentation levels.

Example Algorithm to Trace

// Caribbean scholarship eligibility checker
INPUT gpa, extracurricular, communityService
SET eligible = FALSE
IF gpa ≥ 3.5 THEN
IF extracurricular ≥ 2 THEN
IF communityService ≥ 50 THEN
SET eligible = TRUE
ELSE
SET eligible = FALSE
ENDIF
ENDIF
ENDIF
IF eligible = TRUE THEN
DISPLAY "Scholarship Approved"
ELSE
DISPLAY "Not Eligible"
ENDIF

Trace Table (gpa = 3.8, extracurricular = 3, communityService = 40)

Step Action Variable Values Condition Evaluation Path Taken
1 INPUT values gpa=3.8, ex=3, cs=40 - -
2 SET eligible = FALSE eligible=FALSE - -
3 Check gpa ≥ 3.5 - 3.8 ≥ 3.5 = TRUE Enter outer IF
4 Check extracurricular ≥ 2 - 3 ≥ 2 = TRUE Enter middle IF
5 Check communityService ≥ 50 - 40 ≥ 50 = FALSE Go to ELSE
6 SET eligible = FALSE eligible=FALSE - -
7 Check eligible = TRUE - FALSE = TRUE = FALSE Go to ELSE
8 DISPLAY "Not Eligible" - - Output

Visual Path Tracing

For the values above, the execution path through the nested conditions is:

Start
gpa ≥ 3.5? ✓
extracurricular ≥ 2? ✓
communityService ≥ 50? ✗
eligible = FALSE
eligible = TRUE? ✗
"Not Eligible"
Your Turn: Trace This Algorithm

Trace this algorithm with: temperature = 85, humidity = 75, wind = 25

INPUT temperature, humidity, wind
IF temperature > 80 THEN
IF humidity > 70 THEN
IF wind < 30 THEN
DISPLAY "Heat warning: Stay indoors"
ELSE
DISPLAY "Breezy but hot"
ENDIF
ELSE
DISPLAY "Hot but dry"
ENDIF
ELSE
DISPLAY "Comfortable temperature"
ENDIF

Trace:
1. temperature > 80? 85 > 80 = TRUE → Enter outer IF
2. humidity > 70? 75 > 70 = TRUE → Enter middle IF
3. wind < 30? 25 < 30 = TRUE → Enter inner IF
4. DISPLAY "Heat warning: Stay indoors"
5. Skip ELSE branches
Output: "Heat warning: Stay indoors"

📋 CSEC Tracing Strategy

In CSEC trace tables:

  1. Work systematically line by line
  2. Update variables immediately after assignment
  3. Note condition evaluations (TRUE/FALSE)
  4. Follow indentation levels to track nesting
  5. Check all ENDIF statements to ensure you exit nested blocks correctly
8

When to Use Nesting vs Logical Operators

Guidelines for Choosing

Both nesting and logical operators can solve the same problems, but each has advantages in different situations.

Situation Use Nesting Use Logical Operators
Sequential checks
Where later checks depend on earlier results
✅ Best choice
Inner IF only runs if outer condition is TRUE
❌ Not suitable
All conditions evaluated regardless
Independent checks
All conditions must be TRUE simultaneously
⚠️ Works but verbose
Multiple nested IF-THEN
✅ Best choice
Single IF with AND operator
Multiple exclusive outcomes
Like grading A, B, C, D, F
✅ Best choice
IF-ELSE IF-ELSE structure
❌ Not suitable
Requires complex combinations
Readability
Making logic clear to human readers
✅ When logic is sequential
Shows decision hierarchy
✅ When combining independent conditions
More concise
CSEC exam clarity
Showing understanding to examiners
✅ For complex multi-level decisions
Proper indentation shows structure
✅ For simple combined conditions
Shows operator knowledge

Example Transformation

Converting nested conditions to logical operators (when appropriate):

// Nested version
IF age ≥ 18 THEN
IF citizen = TRUE THEN
IF registered = TRUE THEN
DISPLAY "Can vote"
ENDIF
ENDIF
ENDIF

// Equivalent with AND operator
IF age ≥ 18 AND citizen = TRUE AND registered = TRUE THEN
DISPLAY "Can vote"
ENDIF

When Nesting is Necessary

// This CANNOT be converted to simple AND/OR
INPUT score
IF score ≥ 90 THEN
// Different actions for different score ranges within A
IF score ≥ 95 THEN
DISPLAY "A+ with distinction"
ELSE
DISPLAY "A - Excellent"
ENDIF
ELSE IF score ≥ 80 THEN
DISPLAY "B - Good"
ELSE
DISPLAY "Needs improvement"
ENDIF

🧠 Decision Making Exercise

For each scenario, decide whether to use nesting or logical operators:

  1. Checking if a student is eligible for sports (age ≥ 13 AND medical clearance = TRUE)
  2. Determining hurricane evacuation level based on multiple weather factors
  3. Calculating different discount levels based on membership type AND purchase amount

Suggested Approaches:
1. Logical operators - Simple AND condition
2. Nested conditions - Multiple levels of decisions with different outcomes
3. Combination - Use AND for combined conditions within nested structure for different discount levels

✅ CSEC Exam Strategy

In CSEC exams, show your thinking clearly:

  • Use nesting when the problem description suggests sequential decisions
  • Use logical operators when all conditions are mentioned together
  • When in doubt, use nesting with clear indentation - examiners can follow your logic
  • Always include proper ENDIF statements for each IF
9

Interactive Student Activities

Activity 1: "Which Path Is Taken?"

For this algorithm with values: income = 45000, years = 3, credit = "Good"

INPUT income, years, credit
IF income ≥ 40000 THEN
IF years ≥ 2 THEN
IF credit = "Excellent" THEN
DISPLAY "Loan: $50,000"
ELSE IF credit = "Good" THEN
DISPLAY "Loan: $30,000"
ELSE
DISPLAY "Loan: $15,000"
ENDIF
ELSE
DISPLAY "Need more work history"
ENDIF
ELSE
DISPLAY "Income too low"
ENDIF
A. "Loan: $50,000"
B. "Loan: $30,000"
C. "Loan: $15,000"
D. "Need more work history"
E. "Income too low"

Answer: B. "Loan: $30,000"
Path: income ≥ 40000 (TRUE) → years ≥ 2 (TRUE) → credit = "Excellent" (FALSE) → credit = "Good" (TRUE) → Display "Loan: $30,000"

Activity 2: Error-Spotting in Nested Logic

Find THREE errors in this nested condition pseudocode:

INPUT temp, rain, wind
IF temp > 30 THEN
IF rain > 50 THEN
DISPLAY "Hot and stormy"
ELSE
IF wind > 40
DISPLAY "Hot and windy"
ENDIF
ELSE
DISPLAY "Pleasant weather"

Errors Found:

  1. Missing THEN after "IF wind > 40"
  2. Missing ENDIF for the innermost IF (wind > 40)
  3. Missing ENDIF at the very end (after "Pleasant weather")

Corrected version should have:
- THEN after "IF wind > 40"
- ENDIF after the DISPLAY "Hot and windy"
- ENDIF after DISPLAY "Pleasant weather"

Activity 3: Rewrite Using Logical Operators

🔄 Transformation Challenge

Rewrite this nested condition using logical operators where possible:

INPUT age, grade, attendance
IF age ≥ 16 THEN
IF grade ≥ 80 THEN
IF attendance ≥ 90 THEN
DISPLAY "Eligible for leadership"
ENDIF
ENDIF
ENDIF

Solution using logical operators:

INPUT age, grade, attendance
IF age ≥ 16 AND grade ≥ 80 AND attendance ≥ 90 THEN
DISPLAY "Eligible for leadership"
ENDIF

Why this works: All conditions must be TRUE simultaneously, so AND operator is appropriate. The nested version works but is less concise.

Activity 4: Caribbean Festival Participation Rules

🏝️ Design Challenge

Create pseudocode for a Caribbean festival with these rules:

  • Participants must be 16+ years old
  • If under 18, need parental consent
  • Costume competition has additional rules:
    • Traditional category: Must use authentic materials
    • Creative category: Any materials allowed but must be original
  • Performance competition: Solo or group (different rules for each)

Design nested conditions to check eligibility for different competition categories.

Sample Solution:

INPUT age, parentalConsent, competitionType, category, materials, originality
IF age ≥ 16 THEN
// Check for under 18 needing consent
IF age < 18 AND parentalConsent = FALSE THEN
DISPLAY "Parental consent required"
ELSE
IF competitionType = "Costume" THEN
IF category = "Traditional" THEN
IF materials = "Authentic" THEN
DISPLAY "Eligible for Traditional Costume"
ELSE
DISPLAY "Need authentic materials"
ENDIF
ELSE IF category = "Creative" THEN
IF originality = TRUE THEN
DISPLAY "Eligible for Creative Costume"
ELSE
DISPLAY "Design must be original"
ENDIF
ENDIF
ELSE IF competitionType = "Performance" THEN
// Performance rules would go here
DISPLAY "Performance category selected"
ENDIF
ENDIF
ELSE
DISPLAY "Too young to participate"
ENDIF
10

Common Student Mistakes

❌ Mistake 1: Missing ENDIF Statements

The Error: Forgetting ENDIF for one or more IF statements, especially in deep nesting.

IF condition1 THEN
IF condition2 THEN
action
// MISSING: ENDIF for inner IF
ENDIF // This only closes outer IF

The Fix: Count your IFs and ENDIFs. Each IF needs exactly one ENDIF.

❌ Mistake 2: Poor or Inconsistent Indentation

The Error: Not indenting nested statements, or using inconsistent indentation that hides the logical structure.

IF condition1 THEN
IF condition2 THEN // No indentation!
action1
ELSE
    action2 // Suddenly indented!
ENDIF
ENDIF

The Fix: Use consistent indentation (typically 2-4 spaces per level). CSEC examiners use indentation to understand your logic.

❌ Mistake 3: Overly Complex Nesting

The Error: Creating deeply nested structures (4+ levels) that are hard to read and debug.

IF cond1 THEN
IF cond2 THEN
IF cond3 THEN
IF cond4 THEN
IF cond5 THEN
action
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF

The Fix: Use logical operators (AND, OR) to combine conditions where possible. Consider using ELSE IF for mutually exclusive options.

❌ Mistake 4: Incorrect Logical Operator Selection

The Error: Using AND when OR is needed, or vice versa.

// Trying to check if grade is A OR B
IF grade = "A" AND grade = "B" THEN // WRONG! Can't be both
action
ENDIF

// CORRECT version:
IF grade = "A" OR grade = "B" THEN
action
ENDIF

The Fix: Think carefully about the logic. AND means both must be true. OR means at least one must be true.

❌ Mistake 5: Forgetting to Handle All Cases

The Error: Nested conditions that don't account for all possible combinations of inputs.

INPUT score
IF score ≥ 90 THEN
DISPLAY "A"
ELSE IF score ≥ 80 THEN
DISPLAY "B"
ELSE IF score ≥ 70 THEN
DISPLAY "C"
// What about scores below 70? Missing ELSE!

The Fix: Include a final ELSE clause to handle unexpected or edge cases, or explicitly check all ranges.

✅ Debugging Nested Conditions

When your nested logic isn't working:

  1. Trace with sample values - Use a trace table
  2. Check ENDIF count - Match each IF with an ENDIF
  3. Verify indentation - Ensure it reflects logical structure
  4. Test boundary cases - Values at condition boundaries (exactly 90, etc.)
  5. Simplify - Break complex nesting into smaller, testable parts
11

CSEC Exam Focus

How Nested Conditions Are Tested

📝 Paper 1: Multiple Choice

Expect 2-4 questions on:

  • Predicting output of nested conditional code
  • Identifying correct pseudocode for described logic
  • Choosing appropriate conditions for nested decisions
  • Recognizing errors in nested structures

📝 Paper 2: Structured Questions

Nested conditions appear in:

  • Section I: Definitions and explanations of nesting concepts
  • Section II: Writing pseudocode with multiple decision levels
  • Section III: Algorithm design with complex decision trees

Common task: "Write pseudocode for a grading system that produces A+, A, A-, B+, etc."

📋 Trace Tables

A frequent exam question type: Complete a trace table for nested conditional code.

Key skills tested:

  1. Following execution through multiple decision levels
  2. Updating variable values correctly
  3. Identifying which branches are taken
  4. Determining final output

🔄 Pseudocode Interpretation

You may need to:

  • Explain what given pseudocode does
  • Identify errors in nested logic
  • Modify existing pseudocode to change behavior
  • Convert between nested conditions and logical operators

Exam Technique for Nested Conditions

  • Read carefully: Nested logic questions often have subtle details
  • Use scrap paper: Draw decision trees or trace tables
  • Check ENDIFs: Before finalizing, verify each IF has an ENDIF
  • Test with values: Mentally test your logic with sample inputs
  • Show structure: Clear indentation earns presentation marks

💪 CSEC Success Strategy

For nested condition questions:

  1. Understand the problem - What decisions need to be made?
  2. Identify decision hierarchy - Which decisions depend on others?
  3. Write outermost decision first - Start with the first condition
  4. Work inward - Add nested conditions step by step
  5. Test logic - Check different input combinations
  6. Verify ENDIFs - Count to ensure proper closure
12

CSEC-Style Exam Practice

Attempt these exam-style questions. Answers are hidden - test yourself first!

Question 1 (Multiple Choice)

What is the output when score = 87?

INPUT score
IF score ≥ 90 THEN
DISPLAY "A"
ELSE IF score ≥ 80 THEN
IF score ≥ 85 THEN
DISPLAY "B+"
ELSE
DISPLAY "B"
ENDIF
ELSE
DISPLAY "C or below"
ENDIF
A. A
B. B+
C. B
D. C or below

Answer: B. B+
score ≥ 90? 87 ≥ 90 = FALSE → Go to ELSE IF
score ≥ 80? 87 ≥ 80 = TRUE → Enter nested IF
score ≥ 85? 87 ≥ 85 = TRUE → Display "B+"

Question 2 (Multiple Choice)

Which pseudocode correctly implements: "Display 'Eligible' if age ≥ 18 and either citizen = TRUE or specialPermission = TRUE"?

A. IF age ≥ 18 AND citizen = TRUE OR specialPermission = TRUE THEN DISPLAY "Eligible" ENDIF
B. IF age ≥ 18 AND (citizen = TRUE OR specialPermission = TRUE) THEN DISPLAY "Eligible" ENDIF
C. IF age ≥ 18 THEN IF citizen = TRUE OR specialPermission = TRUE THEN DISPLAY "Eligible" ENDIF ENDIF
D. Both B and C are correct

Answer: D. Both B and C are correct
Option B uses parentheses to group the OR condition. Option C uses nesting. Both correctly implement the logic.

Question 3 (Short Answer)

How many ENDIF statements are needed for this nested structure?

IF condition1 THEN
IF condition2 THEN
action1
IF condition3 THEN
action2
ENDIF
ELSE
action3
ENDIF
ENDIF

Answer: 3 ENDIF statements
The structure has 3 IF statements (lines 1, 2, and 4), so it needs 3 ENDIF statements (lines 7, 9, and 10).

Question 4 (Trace Table Completion)

Complete the trace table for this algorithm with a = 5, b = 3, c = 7:

INPUT a, b, c
IF a > b THEN
IF a > c THEN
SET max = a
ELSE
SET max = c
ENDIF
ELSE
IF b > c THEN
SET max = b
ELSE
SET max = c
ENDIF
ENDIF
DISPLAY max

Trace Table:

Step Condition/Assignment Result/Value max
1 Input values a=5, b=3, c=7 -
2 a > b? (5 > 3) TRUE -
3 a > c? (5 > 7) FALSE -
4 SET max = c - 7
5 DISPLAY max Output: 7 7

Question 5 (Pseudocode Completion)

Complete this algorithm to display appropriate hurricane warnings:

INPUT category, windSpeed
IF category ≥ 3 THEN
IF ________________ THEN
DISPLAY "Major hurricane - EVACUATE"
ELSE
DISPLAY "Dangerous hurricane - PREPARE"
ENDIF
ELSE IF category = 2 THEN
DISPLAY ________________
ELSE
DISPLAY "Monitor conditions"
________________

Answer:

INPUT category, windSpeed
IF category ≥ 3 THEN
IF category ≥ 4 OR windSpeed > 155 THEN
DISPLAY "Major hurricane - EVACUATE"
ELSE
DISPLAY "Dangerous hurricane - PREPARE"
ENDIF
ELSE IF category = 2 THEN
DISPLAY "Strong storm - SECURE PROPERTY"
ELSE
DISPLAY "Monitor conditions"
ENDIF

Note: Other reasonable answers are acceptable for the hurricane warning messages.

Question 6 (Structured Question)

Write pseudocode for a Caribbean airline baggage fee system:

  • First checked bag: Free if weight ≤ 23kg, otherwise $50
  • Second checked bag: $40 if weight ≤ 23kg, $80 if weight > 23kg
  • Third+ checked bag: $100 each regardless of weight
  • Carry-on: Free if ≤ 10kg, otherwise must be checked (apply above rules)

Your algorithm should input baggage count, weights, and calculate total fee.

Sample Solution:

INPUT numBags
SET totalFee = 0
FOR i = 1 TO numBags
INPUT weight, bagType
IF bagType = "carryon" THEN
IF weight > 10 THEN
// Convert to checked baggage
SET bagType = "checked"
ELSE
// Carry-on within limit - free
SET fee = 0
ENDIF
ENDIF
IF bagType = "checked" THEN
// Determine which checked bag this is
IF i = 1 THEN
// First checked bag
IF weight ≤ 23 THEN
SET fee = 0
ELSE
SET fee = 50
ENDIF
ELSE IF i = 2 THEN
// Second checked bag
IF weight ≤ 23 THEN
SET fee = 40
ELSE
SET fee = 80
ENDIF
ELSE
// Third or subsequent bag
SET fee = 100
ENDIF
ENDIF
SET totalFee = totalFee + fee
ENDFOR
DISPLAY "Total baggage fee: $", totalFee

Question 7 (Error Detection)

Find and correct all errors in this nested pseudocode:

INPUT age, gpa
IF age ≥ 16
IF gpa ≥ 3.0 THEN
DISPLAY "Eligible for internship"
ELSE
DISPLAY "GPA too low"
ELSE
DISPLAY "Too young"
ENDIF

Corrected Version:

INPUT age, gpa
IF age ≥ 16 THEN // Added THEN
IF gpa ≥ 3.0 THEN
DISPLAY "Eligible for internship"
ELSE
DISPLAY "GPA too low"
ENDIF // Added ENDIF for inner IF
ELSE
DISPLAY "Too young"
ENDIF

Errors fixed: 1. Added THEN after first IF, 2. Added ENDIF for the inner IF-ELSE structure.

Question 8 (Flowchart Interpretation)

A flowchart shows: Diamond1: "score ≥ 80?" → YES to Diamond2: "score ≥ 90?" → YES to "Display A", NO to "Display B" → NO from Diamond1 to "Display C or below". Write the corresponding pseudocode.

Pseudocode:

INPUT score
IF score ≥ 80 THEN
IF score ≥ 90 THEN
DISPLAY "A"
ELSE
DISPLAY "B"
ENDIF
ELSE
DISPLAY "C or below"
ENDIF

📊 How Did You Do?

7-8 correct: Excellent! You've mastered nested conditions.

5-6 correct: Good understanding. Review the specific question types you missed.

3-4 correct: You understand the basics but need more practice with complex nesting.

0-2 correct: Review the key concepts and examples, then try again.

13

Summary & Next Steps

Key Takeaways

  • Nested conditions allow multi-level decision making in algorithms
  • Each IF statement needs exactly one ENDIF (matching pairs)
  • Proper indentation is crucial for readability and exam marks
  • Logical operators (AND, OR, NOT) can often simplify nested structures
  • Use nesting for sequential decisions, logical operators for simultaneous conditions
  • Always trace your logic with sample values to verify correctness

CSEC IT Syllabus Connection

You've now mastered a critical component of Module 1: Problem Solving with Computers. Complex decision making is essential for:

  1. Developing sophisticated algorithms for real-world problems
  2. Creating programs that handle multiple input conditions
  3. Designing systems with hierarchical decision structures
  4. Writing clear, maintainable pseudocode for CSEC exams

🚀 Apply Your Knowledge

Design a complete Caribbean-themed system using nested conditions. Choose one:

  • A crop irrigation system that considers rainfall, soil moisture, and crop type
  • A tourism recommendation system based on season, budget, and interests
  • A sports competition bracket system with multiple elimination rounds
  • A natural disaster response system with multiple threat levels

Include at least three levels of nesting and test with various input combinations!

What's Next in CSEC IT?

After mastering nested conditions, continue with:

  1. Iteration Structures - FOR, WHILE, REPEAT loops with nested conditions
  2. Arrays and Lists - Processing collections with conditional logic
  3. Modular Programming - Creating reusable decision-making procedures
  4. File Processing - Making decisions based on data from files

🎯 Final Exam Preparation Tip

Practice converting real-world Caribbean scenarios into pseudocode with nested conditions. Examiners appreciate algorithms that solve relevant, contextual problems. Remember: Clear logic beats clever but confusing code every time!

Additional Resources

  • CSEC IT Syllabus (Section 1.4.2: Complex Decision Structures)
  • Past paper questions on nested conditions (2015-2023)
  • Online pseudocode validators and tracers
  • Decision tree diagramming tools for visualizing complex logic

🧠 Final Challenge

Explain the concept of nested conditions to a younger student without using programming terminology. Create an analogy using everyday Caribbean decision-making (like choosing what to do based on weather, time, and transportation). If you can explain it simply, you truly understand it!

Scroll to Top