Skip main navigation

What is Selection?

What is selection and why is it important for programming? Read this article to find out

So far, the programs you’ve written have performed exactly the same task each time they are run. Selection involves your program asking a yes/no question, and using the answer to decide what to do next.

Here are a few examples of selection in everyday life.

When you leave for work each morning, you’ll probably take a look out of the window and ask yourself the question “Is it raining?”. If you’re really organised you may even take a look at the weather forecast and ask yourself the similar question “Is it likely to rain today?”.

Either way, you will use the answer to this question to decide what to do next. If the answer is “yes” you will grab your umbrella before you leave the house. If the answer is “no” you’ll leave it at home.

Grabbing an Umbrella

When playing a game of “Simon Says”, each time an instruction is given to you, you’ll ask yourself the question “Did the instruction start with the words ‘Simon says’?”. If the answer is “yes”, you will follow the instructions given to you, otherwise you will do nothing.

If you’ve ever painted by numbers, you’ll know that you’re constantly using information to decide what colour each section should be painted.

Paint by Numbers

The decisions made will look something like this:

  • if the number is 1 then paint the section red
  • if the number is 2 then paint the section blue
  • if the number is 3 then paint the section yellow
  • etc.

As in the previous examples, you are using the answer to a question (such as “Is the number 1?”) to select your next action.

This article is from the free online

Teaching Programming in Primary Schools

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education