Knowledge Organiser: Selection
Key Terms
- Selection: A programming construct that executes different code depending on a condition
- IF statement: Runs a block of code only if a condition is true
- ELSE: The block that runs when the IF condition is false
- ELSEIF: Checks an additional condition when the previous one is false
- SWITCH/CASE: Compares one variable against many specific values
- Nesting: Placing one IF statement inside another IF statement
Must-Know Facts
- Every IF must be closed with ENDIF
- Use == for comparison in conditions, not = (which is assignment)
- ELSEIF checks are tested in order — first true condition wins
- SWITCH/CASE is cleaner than many ELSEIFs when testing one variable
- Indentation shows the structure of nested IF statements
- DEFAULT in SWITCH runs if no CASE matches
Key Concepts
- Basic IF: if condition then ... endif
- IF-ELSE: if condition then ... else ... endif
- IF-ELSEIF: if ... then ... elseif ... else ... endif
- SWITCH: switch var: case "X": ... default: ... endswitch
- Combine conditions: if username == "admin" AND password == "secret" then
Common Mistakes
- Using = instead of == for comparison: In pseudocode conditions, == tests equality; = assigns a value — writing if age = 18 instead of if age == 18 is a common error
- Forgetting ENDIF: Every IF statement must be closed with ENDIF — omitting it loses marks in pseudocode questions
- Putting ELSEIF after ELSE: ELSE must always come last — ELSEIF conditions go between IF and ELSE, not after it
- Not indenting nested IF statements: Each level of nesting should be indented consistently — poor indentation makes logic errors hard to spot and loses presentation marks
- Using IF-ELSEIF chains when SWITCH/CASE is cleaner: When testing one variable against many fixed values, SWITCH/CASE is clearer — examiners may expect it for multi-way selection questions