Studyfin Studyfin ✨ Sign up free

Conditionals

Grade 8 · Coding · Free lesson

Hey there! Ready to learn how code makes smart decisions? Let's explore conditionals together!

In coding, we use a design process to solve everyday problems. When we want our program to make a choice, we use a tool called a conditional statement.

school

A conditional statement is like an 'If-Then' rule. If a condition is true, then the computer runs a specific block of code.

Is it raining? Umbrella YES

We can also add an 'Else' part. If the condition is false, the computer skips the first choice and does the 'Else' action instead.

Score > 10? YES Show "You Win!" NO Show "Try Again"
✏️ Worked example

Let's design a program to help a smart greenhouse decide when to water a plant. We want to water the plant only when the soil moisture level falls below 40 percent.

  1. Identify the problem: The plant needs water, but only when the soil is dry.
  2. Define the condition: We will measure the soil moisture percentage.
  3. Set the threshold: Our condition is 'Is moisture less than 40?'
  4. Write the If-statement: If moisture < 40, then turn on the water pump.
  5. Write the Else-statement: Else, keep the water pump turned off.
run
Want the full interactive lesson — quiz, animations, and Finn cheering them on?

More Coding lessons