Choose exam board for KS4 Computer Science (GCSE)
Choose exam board for KS4 English
Choose exam board for KS4 French
Choose exam board for KS4 Geography
Choose exam board for KS4 German
Choose exam board for KS4 History
Choose tier for KS4 Maths
Choose exam board for KS4 Music
Choose exam board for KS4 Physical education (GCSE)
Choose exam board for KS4 Religious education (GCSE)
Choose exam board for KS4 Spanish

      Lesson details

      Learning outcome

      I can trace and modify code in a program that uses nested selection.

      Key learning points

      1. Selection statements with conditions can be nested inside another selection statement.
      2. Nested selection statements are used to implement complex branching logic.
      3. If a condition of a main selection block evaluates to True, it leads to sub-conditions which are inside the main block.

      Keywords

      • Nested selection - a block of code where a selection block is placed within another selection block

      Common misconception

      A nested selection statement can only have one nested selection block.

      Selection statements can can continue to be nested in further selection blocks to provide more complex conditions for which specific code will be executed.

      Teacher tip

      The second part of the lesson requires pupils to modify an existing program. Encourage learners to run the code a few times to investigate how it works before answering the questions.

      Equipment

      Pupils will need access to a device that can edit and run Python programs. Examples in this lesson use the RPF Code Editor https://oak.link/python-editor

      Licence

      This content is © Oak National Academy Limited (2026), licensed on Open Government Licence version 3.0
      except where otherwise stated. See Oak's terms & conditions
      (Collection 2).

      Lesson video

      Loading...

      Prior knowledge starter quiz

      6 Questions

      Q1.
      Which of the following expressions will return False?

      Correct answer: 3 > 4
      (3+10) < (3*10)
      (5-2+10/2) == 8
      Correct answer: (2+10) != (6*2)

      Q2.
      Which of these statements would return True for the following card?

      An image in a quiz
      Correct answer: value > 6
      value != 10
      Correct answer: value == 10
      value <9

      Q3.
      The three logical operators are 'and', 'or' and ' '.

      Correct Answer: not

      Q4.
      Logical operators can be used alongside relational operators to build logical when more values need to be compared.

      Correct Answer: expressions, xpressions

      Q5.
      Which expressions would return True for this card?

      An image in a quiz
      value == "king" and suit == "hearts"
      value == 9 and suit == "hearts"
      Correct answer: value == 9 and suit == "diamonds"
      Correct answer: value == "king" or suit == "diamonds"

      Q6.
      Arithmetic expressions evaluate to a number. Logical expressions evaluate to .

      Yes or No
      Correct answer: True or False
      0 or 1

      6 Questions

      Q1.
      What is nested selection in programming?

      A type of loop that repeats a block of code.
      A way to store multiple values in a list.
      A selection statement with multiple branches.
      Correct answer: A selection statement placed inside another selection statement.

      Q2.
      What does the lower() method do when used on a string in Python?

      Converts all letters to uppercase.
      Correct answer: Converts all letters to lowercase.
      Checks if the string contains numbers.
      Removes spaces from the string.

      Q3.
      In nested selection, if the outer condition is `False`, the inner condition will .

      Correct answer: not execute.
      execute.
      cause an error.

      Q4.
      What would be displayed if the user enters "Jun" for the username?

      An image in a quiz
      Password:
      Access granted
      Correct answer: ...program closing

      Q5.
      What would be displayed if the user enters "Izzy" for the username and then "Dog1234" for the password?

      An image in a quiz
      Correct answer: Password: ...program closing
      Password: Access granted
      ...program closing

      Q6.
      What would be displayed if the user enters "Izzy" for the username and then "Fish4321" for the password?

      An image in a quiz
      Correct answer: Password: Access granted
      ...program closing
      Password: ...program closing

      To help you plan your 10 computer science lesson on: Nested selection, download all teaching resources for free and adapt to suit your pupils' needs...