πŸ€–
πŸ’» Technology ⏱ 3 min read

If-Then: How Computers Make Decisions

Learn how if-then statements let computers make choices and decisions, just like you do every day.

Age 9–12
KS2 Computing Ages 9-12
Reading level: |

What Is an If-Then Statement?

An if-then statement is a simple rule that tells a computer what to do. It works in two parts: first comes the condition (the "if" part), and then comes the action (the "then" part). The computer checks whether something is true, and if it is, the computer does something in response.

Think of it this way: if you are hungry, then you eat a snack. The computer works exactly like this! It checks a condition, and when that condition is true, it performs an action.

Think of it like a traffic light. If the light is red, then you stop. If the light is green, then you go. The traffic light has a simple rule that decides what drivers should do.

How Do Computers Use If-Then?

Computers use if-then statements thousands of times every second to make decisions. When you play a video game, if-then statements check whether you've jumped on an enemy. When you use social media, if-then statements decide whether to show you a "like" notification. If-then statements power almost everything digital you interact with.

A simple example: if your password is correct, then let you log in. If your password is wrong, then show an error message. The computer doesn't "think" about this β€” it just follows the rule automatically.

Think of it like a vending machine. If you insert enough money, then the machine gives you a snack. If you don't insert enough money, then nothing happens. The machine follows its rules without thinking.

Why Are If-Then Statements Important?

If-then statements are the building blocks of all programming and coding. They let programmers (people who write computer instructions) create games, apps, websites, and artificial intelligence. Without if-then statements, computers couldn't make decisions on their own.

When you use your smartphone, hundreds of if-then statements are running behind the scenes. If you tap a button, then an app opens. If your battery is low, then a warning appears. If you receive a message, then a sound plays. All of these are if-then statements working together.

Think of it like a recipe. If you want chocolate chip cookies, then you add chocolate chips to the dough. If you want plain cookies, then you skip the chocolate chips. Following different rules creates different results, just like different if-then statements make computers behave differently.

Learning to Code

When you start learning to code in school, if-then statements are usually the first thing you'll learn. Once you understand this simple idea, you can create your own programs and games. It's one of the most powerful tools in computing, and it all starts with this one simple rule: if something is true, then do something else.

Test yourself 🧠

This quiz is calibrated for KS2 Computing.