← Computer Science

Selection: how programs make decisions

Selection is how a program chooses between different actions depending on the data. In this lesson we cover the IF statement in all its forms, the CASE OF statement, and how to build the Boolean conditions that drive those decisions.

Slide 1 / 4

Why programs need selection

Selection chooses a path from a conditionmark >= 40 ?TRUEOUTPUT "Pass"FALSEOUTPUT "Fail"
  • Sequence alone runs every line in order; selection lets a program take one path OR another depending on the data.
  • A condition is a question with a true or false answer, for example is the mark 40 or more.
  • The program tests the condition, then runs one block of statements if it is true and possibly a different block if it is false.
  • Everyday examples: award a pass or a fail, charge child or adult price, unlock a door only if the password matches.

Check you've got it

0/4

1. In Cambridge pseudocode, which operator means not equal to?

2. A program must output a different message for exam grades A, B, C, D and E based on a single grade variable. Which structure is usually the clearest?

3. Trace this code with mark set to 64. What is output? mark <- 64 IF mark >= 70 THEN grade <- "A" ELSE IF mark >= 60 THEN grade <- "B" ELSE grade <- "C" ENDIF ENDIF OUTPUT grade

4. The condition NOT (x > 5) is true for which values of x?

Practise real exam questions on this

Type your answer, see your mark against the mark scheme in seconds. Free, 5 a day.

Start practising →

Teaching this topic?

Mark your whole class's answers and see who's stuck, for £19 a month.

See the class plan →

Free revision content. Multiple-choice answers are marked instantly. Written answers are marked by AI on /free-mark.