- Home
- /
- Computational Thinking
- /
- Computational Thinking
- /
- Selection
Selection
Also known as: conditional, if-then, branching
Grade 6-8
View on concept mapChoosing which block of code to execute based on whether a condition is true or false. Selection enables programs to respond differently to different situations.
Definition
Choosing which block of code to execute based on whether a condition is true or false. Selection allows programs to make decisions, following one path when a condition holds and a different path otherwise, using constructs like if, else-if, and else.
💡 Intuition
If this is true, do that path. If it is false, take a different path instead.
🎯 Core Idea
Programs can choose between different execution paths depending on the current data values.
Example
🌟 Why It Matters
Selection enables programs to respond differently to different situations. Without conditionals, every program would do the exact same thing every time it runs, making interactive software, error handling, and decision-based logic impossible.
💭 Hint When Stuck
When writing a conditional, first identify the exact condition to test and make sure it evaluates to true or false. Then write the code for the 'true' branch, and consider whether you need an 'else' branch for the false case. Always check boundary values where the condition flips.
Formal View
Related Concepts
🚧 Common Stuck Point
Conditions must be unambiguous—what happens when temperature = 30?
⚠️ Common Mistakes
- Using assignment (=) instead of comparison (==) in the condition, which silently succeeds in some languages
- Forgetting to handle the else case, leaving unexpected inputs with no defined behavior
- Writing overlapping conditions in if/else-if chains so that the wrong branch executes
Frequently Asked Questions
What is Selection in CS Thinking?
Choosing which block of code to execute based on whether a condition is true or false. Selection allows programs to make decisions, following one path when a condition holds and a different path otherwise, using constructs like if, else-if, and else.
When do you use Selection?
When writing a conditional, first identify the exact condition to test and make sure it evaluates to true or false. Then write the code for the 'true' branch, and consider whether you need an 'else' branch for the false case. Always check boundary values where the condition flips.
What do students usually get wrong about Selection?
Conditions must be unambiguous—what happens when temperature = 30?
Prerequisites
Next Steps
How Selection Connects to Other Ideas
To understand selection, you should first be comfortable with sequence. Once you have a solid grasp of selection, you can move on to boolean logic and nested conditionals.
💻 Interactive Visualization
Adjust temperature to see different code paths execute