Studyfin Studyfin ✨ Sign up free

Conditionals

Grade 5 · Coding · Free lesson

Hi there! I am Studyfin, your coding buddy. Today, we will learn how to make smart decisions in our programs!

Have you ever decided to wear a coat because it was raining? In coding, we call this a conditional. It lets our program make decisions based on real-life events.

We use 'If-Then' rules to tell the computer what to do. If a condition is true, then the computer runs a specific block of code.

IF it rains... THEN use umbrella!

What if it is NOT raining? We can use 'Else' to give a backup plan! This keeps our code running smoothly in all situations.

ELSE (Sunny)... Wear sunglasses!
✏️ Worked example

We want to design a program for an automatic nightlight. The light should turn on only when it gets dark in the room. Let us build this step-by-step using our design process.

  1. First, find the everyday problem: We want to save electricity by keeping the light off during the day.
  2. Second, name the condition: We need to check if the room is dark.
  3. Third, write the 'If' block: If the light sensor value is less than 10 (which means it is dark).
  4. Fourth, write the 'Then' action: Turn the nightlight bulb ON.
  5. Fifth, write the 'Else' action: Turn the nightlight bulb OFF when it is bright.
  6. Finally, test your program with a loop so it checks the light level constantly!
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons