Selection: If Statements
Selection lets a program make decisions by running different code depending on whether a condition is true.
▶ Interact
Play with the controls to see the idea in action.
📘 Learn
Selection lets a program make decisions by running different code depending on whether a condition is true.
- IF, ELSE IF and ELSE
- Conditions give true or false
- Nested selection handles complex choices
🧠 Quick quiz
Three questions. Score 2 or more to complete the topic.
What is Selection: If Statements?
Within Computer Science, which covers algorithms, programming, data, networks, hardware and safe, responsible use of technology, this topic explains Selection: If Statements. Computing topics explain how software, hardware and data work, with diagrams and models that show each step in order.
Check that you can explain Selection: If Statements in your own words and give one example from everyday life. If you can do that, you have understood the core idea.
Understanding Selection: If Statements helps you design, test and explain programs, websites and systems, from small projects to exam questions.
Selection: If Statements in detail
Selection lets a program choose between different paths depending on a condition. An IF statement runs a block of code only if a condition is true, and ELSE gives an alternative when it is false. ELSE IF (elif) chains check several conditions in order.
For example: IF score >= 50 THEN print "Pass" ELSE print "Fail". Conditions can be combined with AND, OR and NOT, and statements can be nested inside each other. A switch or case statement is another form of selection. Selection lets programs respond to input, make decisions and handle different cases, so it is one of the three basic building blocks, with sequence and iteration.
How the interactive helps you understand Selection: If Statements
Click a step, or use the Previous and Next buttons, to move through the sequence one stage at a time. Auto-play moves on for you.
Before you change anything, predict the result. Then change one value at a time and check whether your prediction was right. This is a quick way to build a correct mental model of Selection: If Statements.
Real-life uses and examples
- Recognise Selection: If Statements in an app or device you use every day.
- Apply Selection: If Statements when you design a small program, website or spreadsheet.
- Explain Selection: If Statements to someone new to computing by comparing it to a familiar process.
Common mistakes to avoid
- Using the term without being able to say what the computer actually does.
- Testing only the normal case and forgetting the edge cases.
- Learning the definition without testing it. Use the quiz and the interactive to check that you can apply the idea.
Frequently asked questions about Selection: If Statements
What is Selection: If Statements?
Selection lets a program make decisions by running different code depending on whether a condition is true.
What are the most important points about Selection: If Statements?
The main points are: IF, ELSE IF and ELSE; Conditions give true or false; Nested selection handles complex choices.
Why is Selection: If Statements useful?
Understanding Selection: If Statements helps you design, test and explain programs, websites and systems, from small projects to exam questions.
How can I practise Selection: If Statements?
Open the interactive at the top of this page and change the controls one at a time. Predict the result before each change, then take the three-question quiz. A score of two or more marks the topic as complete on this device.
Which topics are related to Selection: If Statements?
Related topics in Computer Science include Strings and String Handling, Input and Output in Programs, Types of Programming Error.