Skip to content
Computer Science · Grade 9

Active learning ideas

Advanced Conditional Logic (Else If, Switch)

Active learning works because conditional logic is best understood through hands-on problem solving. Students need to trace, write, and critique code to see how 'else if' and 'switch' control flow in real programs. These activities put students in the driver’s seat, making abstract logic concrete through collaborative tasks and immediate feedback.

Ontario Curriculum ExpectationsCS.HS.AP.7CS.HS.CT.8
25–45 minPairs → Whole Class4 activities

Activity 01

Problem-Based Learning30 min · Pairs

Pair Programming: Grade Calculator

Pairs write a program using 'if-else if-else' to assign letter grades based on numeric scores. Test with sample inputs, then add 'switch' for bonus categories like pass/fail. Discuss which structure reads more clearly.

Compare the efficiency and readability of 'if-else if' chains versus 'switch' statements.

Facilitation TipDuring Pair Programming: Grade Calculator, circulate to ask each pair: 'How did you decide where to place each condition in the chain?' to reinforce sequential logic.

What to look forPresent students with a scenario, such as a simple grading scale (e.g., 90+ A, 80-89 B, etc.). Ask them to write pseudocode or actual code using 'else if' to represent this logic. Then, ask them to rewrite the same logic using a 'switch' statement if applicable, or explain why 'else if' is more suitable.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 02

Problem-Based Learning45 min · Small Groups

Small Groups: Menu Selector Challenge

Groups build a text-based menu using 'switch' for options like 'play', 'quit', or 'help'. Convert to 'if-else if' chain and time execution on varied inputs. Vote on the best version for maintenance.

Design a program that handles multiple distinct conditions using appropriate control structures.

Facilitation TipFor the Small Groups: Menu Selector Challenge, provide a starter code with intentional errors in the 'switch' structure to prompt collaborative debugging.

What to look forProvide students with two code snippets solving the same problem: one using a long 'if-else if' chain and another using a 'switch' statement. Ask them to discuss in pairs: Which code is easier to read? Which is more efficient for this specific problem? What are the advantages and disadvantages of each approach?

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 03

Problem-Based Learning35 min · Whole Class

Whole Class: Code Critique Gallery Walk

Project 4-5 anonymized code snippets with flawed conditionals. Class walks gallery, notes issues on sticky notes, then votes and refactors as a group using optimal structures.

Critique a given code snippet for its optimal use of conditional logic.

Facilitation TipDuring the Whole Class: Code Critique Gallery Walk, assign each group a role: reviewer, responder, or facilitator to keep discussions focused and equitable.

What to look forGive each student a card with a programming task, e.g., 'Handle user input for days of the week (Monday-Sunday)' or 'Categorize a score into ranges (0-50, 51-75, 76-100)'. Ask them to write one sentence explaining which structure ('if-else if' or 'switch') they would use and why, and then provide one line of code demonstrating its basic structure.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

Activity 04

Problem-Based Learning25 min · Individual

Individual: Logic Puzzle Debugger

Provide buggy code with nested conditionals. Students trace execution on paper first, then code fixes using 'switch' where possible. Share one fix with the class.

Compare the efficiency and readability of 'if-else if' chains versus 'switch' statements.

Facilitation TipFor the Individual: Logic Puzzle Debugger, give students a dry-erase board to sketch execution paths before rewriting code to make logic visible.

What to look forPresent students with a scenario, such as a simple grading scale (e.g., 90+ A, 80-89 B, etc.). Ask them to write pseudocode or actual code using 'else if' to represent this logic. Then, ask them to rewrite the same logic using a 'switch' statement if applicable, or explain why 'else if' is more suitable.

AnalyzeEvaluateCreateDecision-MakingSelf-ManagementRelationship Skills
Generate Complete Lesson

A few notes on teaching this unit

Teach conditional logic by having students compare equivalent solutions side by side. Start with a simple problem, then show how 'else if' and 'switch' solve it differently. Avoid teaching syntax first—instead, emphasize the decision-making process. Research shows that students grasp control flow faster when they see it as a tool for organizing choices, not just a coding pattern.

Successful learning looks like students confidently choosing between 'if-else if-else' and 'switch' based on the problem. They should explain their choices clearly and debug errors in peers’ logic without prompting. By the end, students can refactor nested chains into cleaner structures and justify their decisions.


Watch Out for These Misconceptions

  • During Pair Programming: Grade Calculator, watch for pairs assuming 'else if' checks even when the prior 'if' is true.

    Have students trace a sample grade through the code on a whiteboard, marking which conditions execute and which are skipped. Ask them to write the execution path in plain English to reinforce sequential evaluation.

  • During Small Groups: Menu Selector Challenge, watch for students limiting 'switch' to numeric cases only.

    Provide a starter code with string-based cases (e.g., 'menuOption = "pizza"') and ask students to convert it from a long 'if' chain to a 'switch'. Highlight that modern languages support strings directly.

  • During Whole Class: Code Critique Gallery Walk, watch for students assuming 'if-else if' chains are always the best choice for complex decisions.

    Provide two versions of the same code: a deep chain and a flattened structure using 'switch' or early returns. Have students annotate which is easier to maintain and why, using clear metrics like line count or condition readability.


Methods used in this brief