Using Selection in Programs

Using Selection in Programs

1 / 34
volgende
Slide 1: Slide
newEditorComputingPrimary Education

In deze les zitten 34 slides, met interactieve quizzen en tekstslides.

time-iconLesduur is: 50 min
Dit is niet oké

Onderdelen in deze les

Using Selection in Programs

Deze slide heeft geen instructies

Learning goal

I can use if and if-else to make a program choose what to do.

Deze slide heeft geen instructies

What words come to mind when you hear coding decisions?

Use this to activate prior knowledge. Accept ideas such as choice, rule, true, false, button, answer, game or traffic lights, then link them to selection.

Lesson introduction

This KS2 computing lesson explores Using Selection in Programs. Pupils use if and if-else decisions to make programs respond differently to conditions and user input. It is suitable for classroom teaching, independent practice or a clear recap of the topic.

Deze slide heeft geen instructies

What does selection mean?

Selection means a program chooses between actions.


It checks a condition such as true or false and then decides what to do next.

Link to everyday choices pupils know, such as 'if it is raining, take a coat'. Keep the focus on computing: the computer follows rules we give it.

Programs do not always do the same thing

A program can respond to:

  • what a user types

  • which button is pressed

  • a score or number

  • whether something is true or false


Selection helps the program give the right response.

Deze slide heeft geen instructies

Selection in real life

We use rules like these every day:

  • if the light is green, go

  • if the light is red, stop

  • if it is cold, wear a jumper


Programs use similar decision rules.

This slide activates prior knowledge without making it an interactive task. Emphasise that computers do not guess; they follow exact conditions.

A condition checks something

A condition is a check.


Examples:

  • score is greater than 9

  • answer equals 12

  • button is pressed

  • password is correct


The result is either true or false.

Pupils may say 'right or wrong'. Accept this, then connect it to true and false in code.

What does selection let a program do?

A

Choose an action

B

Draw a picture

C

Charge a battery

D

Print a keyboard

Checks the core idea from slides 3 to 6: selection means choosing between actions after checking a condition.

Complete the selection words

A program uses selection to choose between actions. It checks a condition and the result is either true or false.

selection
condition
true
false
output
input
score
button

Support lower-attaining pupils by revisiting the everyday examples from traffic lights and getting dressed for the weather.

Using if

An if statement tells a program:


If a condition is true, do something.


If the condition is false, the program skips that action and carries on.

Deze slide heeft geen instructies

Example of if

```text

if score > 9

say "You win!"

```


The message only appears when the score is more than 9.

You do not need to teach a specific programming language here. Treat the code as simple pseudocode pupils can read.

Using if-else

An if-else statement gives two possible actions.


  • if the condition is true, one action happens

  • else a different action happens


This helps a program respond in more than one way.

Deze slide heeft geen instructies

Example of if-else

```text

if answer = 10

say "Correct"

else

say "Try again"

```


The program always gives one of the two messages.

Highlight the contrast with plain if: with if-else, something happens whether the condition is true or false.

What happens with only an if statement when the check is false?

A

It repeats the check

B

It shows both actions

C

It skips the action

D

It stops the program

Tests the contrast taught on slides 7 and 8: plain if only runs when true; otherwise the action is skipped.

Why is if-else useful?

A

It stores the input

B

It gives two actions

C

It draws the screen

D

It changes the keyboard

This checks understanding of the key difference between if and if-else from slides 9 and 10.

How is if-else different from if?

Expected elements: an if statement has one action only when the condition is true; an if-else gives one action when true and a different action when false. Encourage pupils to use a simple example such as score, answer or button pressed.

User input can change the result

When a user clicks, types or chooses something, the program can check it.


That input becomes part of the condition, so the output can change.

Use familiar examples such as a quiz, a login, or choosing an answer in a game.

Selection in a quiz game

A quiz might work like this:


user answer → program checks answer →

correct answer gives one message

wrong answer gives a different message


Selection makes the quiz feel responsive.

Deze slide heeft geen instructies

Selection in a simple game

A game can use rules such as:

  • if lives = 0, show Game over

  • if score > 99, show Level up

  • else keep the game going


These decisions help control what happens next.

Deze slide heeft geen instructies

In a quiz, what can the program check first?

A

The table colour

B

The user answer

C

The classroom door

D

The pencil case

Anchored to slides 11 to 13 about user input in quizzes and games.

Fill the quiz rule

In a quiz, the user types an answer. The program checks the input and gives an output that can change if the answer is correct or wrong.

user
input
output
correct
screen
mouse
level
false

This acts as an application task in familiar context. Pupils apply vocabulary from the content to the quiz example.

Which example of selection do you understand best?

1

Quiz answer

2

Game score

3

Button press

4

Password check

Deze slide heeft geen instructies

Why selection matters

Without selection, every program would do the same thing every time.


Selection helps programs:

  • react to input

  • check rules

  • give different outputs

  • feel useful and interactive

Deze slide heeft geen instructies

Common mistakes to avoid

Watch out for these errors:

  • the condition is unclear

  • the wrong action is inside if

  • else is missing when two outcomes are needed

  • the program checks the wrong input


Good selection needs clear rules.

If useful, model a faulty rule and ask what would happen. Keep explanation brief because interactions are handled later.

Planning a selection rule

Before coding, think about:

  1. What needs to be checked?

  2. What makes the condition true?

  3. What should happen if it is true?

  4. What should happen if it is false?


This helps you design the program clearly.

This supports later application work the teacher may run, while staying content-focused in this pass.

From rule to code

Everyday rule:

If the password is correct, open the page. Else, show an error.


Program rule:

  • check the input

  • compare it with the correct password

  • choose the matching action

Stress that selection is about turning a rule into a precise computer instruction.

When do you need else most?

A

When two outcomes are needed

B

When no input is checked

C

When the screen is blank

D

When the code is colourful

Based on slides 14 to 17 and the mistakes slide. The misconception is thinking else is always needed, rather than when there are two outcomes.

Complete the planning steps

Before coding, plan the condition first. Decide what makes it true, then choose the action for true and the action for false. This turns a rule into clear code.

condition
true
false
code
input
score
jumper
button

Useful for differentiation: invite confident pupils to invent their own rule after completing the blanks, while others can rehearse the four planning questions aloud.

What rule would you plan before coding?

Expected elements: identify what is checked, what makes it true, what happens if true, and what happens if false. Accept everyday or computing examples, especially password, score or answer examples from slides 16 and 17.

What is one thing you learned today?

Reflection only. Invite brief answers about if, if-else, conditions, input or outputs.

What helped you understand selection best?

Reflection only. This helps the teacher see which explanation, example or activity supported understanding best.

How confident do you feel about using if and if-else now?

Deze slide heeft geen instructies

Glossary

selection - when a program chooses between actions

condition - a check that is either true or false

if - a command that runs an action when a condition is true

if-else - a command with one action for true and another for false

user input - information a person gives to a program

output - what a program shows, says or does

pseudocode - simple code-like writing used to plan a program

Deze slide heeft geen instructies