Computer Science glossary · Grade 2 to Grade 9
Selection
Also called: branching, decision, conditional, if statement
What it means
Selection is when a program makes a decision. It checks whether something is true or false and then chooses which steps to follow, often using "if ... then ... else".
Examples
- If it is raining, take an umbrella, else wear a hat.
- In a game: if the player touches the coin, add 1 to the score.
- A quiz program: if the answer equals 12, say "Correct!", otherwise say "Try again".
For teachers
Selection (also called branching) lets an algorithm take different paths depending on a condition, which must be either true or false. In a flowchart it appears as a diamond with two exits labeled yes and no. Younger students can act out branching stories ("If it is raining, take an umbrella; otherwise wear a hat"); older students write if, if-else and nested conditions in block or text-based code and test every branch.
Common misconception
Students sometimes test only the path they expect and forget the other branch. Every selection has at least two possible paths, and a program is only correct if each path does the right thing, so both need to be tested.