Selection

Also known as: conditional, if-then, branching

structure

Choosing which block of code to execute based on whether a condition is true or false. Enables programs to respond differently to different situations.

💡 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

IF temperature > 30°C THEN turn on AC, ELSE turn off AC. Two different paths, one condition.

🎯 Why It Matters

Enables programs to respond differently to different situations.

⚠️ Common Confusion

Conditions must be unambiguous—what happens when temperature = 30?

Related Concepts

Prerequisites

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.

Learn More

Go Deeper

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.

Why is Selection important?

Enables programs to respond differently to different situations.

What do students usually get wrong about Selection?

Conditions must be unambiguous—what happens when temperature = 30?

What should I learn before Selection?

Before studying Selection, you should understand: sequence.

💻 Interactive Visualization

Temperature: 50°C

Adjust temperature to see different code paths execute