Conditional statements in Scratch programming

Fatima Z on February 25, 2023

Conditional statements in Scratch programming


Scratch programming language includes conditional statements that help determine whether a condition set by the the programmer is true or false. These conditional statements in Scratch allow developers to compare variables or test them against specific values and control how the program behaves based on whether the condition is met.

With these robust control structures, Scratch offers excellent flexibility, enabling developers to create various projects, from simple calculators to complex robots.
In this blog, we’ll dive into the details of Scratch’s conditional blocks, exploring their functionality and potential applications. Keep reading to learn more.

What are conditional statements?

Let’s say you have a lightbulb and want to get it working. So you flip the switch to ‘on’ – but if nothing happens, the bulb needs replacing, or something’s not connected correctly. So you just have to check the situation and act accordingly – just like with conditional statements in Scratch!
A chart for better understanding

Conditionals in scratch


Flowcharts are fantastic for organizing your thoughts and seeing all the steps in a process. They help you understand what’s going on, even if it looks complicated.

Plus, you can use them to spot loop holes or flaws before getting down to the gritty details. Whenever you’re starting a project, flowcharting is a must! It’ll make writing the actual script so much easier.

Best Online Coding class for kids

What are conditional statements in Scratch?

They’re instructions that tell the computer to do something if something else is true. Here’s a rundown of each type of condition:

1. If-Then () bricks in Scratch
The if-then brick is a dope control block on the old Scratch platform. The code will check to see if the condition listed is true or false – if it’s true, then it’ll execute the program. Watch out so that even if the condition changes while running, you can’t count on your code to recognize this!

conditional statement in scratch

2 – If-Then else () block in Scratch
Scratch’s If-Then-Else block is an upgrade from the basic If-Then block. If you have some code in the “If” and “Else” parts, Scratch will decide which one to run based on whether the condition is true or false. I’ll think about it quickly; it goes with whichever works best.

If-Then Else () Block in Scratch

Let’s talk about other blocks that Scratch has!
Repeat blocks in Scratch
Just drop in a number and set the looping fun to begin. No more worries about figuring out how many times you need it to do a task—it’s taken care of for you. But, of course, the result will always be rounded up, so if you want your program to repeat precisely five times, add 0.99 to that number for the perfect repeat block in Scratch.

Repeat blocks in scratch

Forever blocks in Scratch
The forever blocks in Scratch will keep the code looping until you hit that stop sign. It’s like Repeat Repeat ( ), except this never ends. No bump at the bottom, meaning any blocks below it will never run.

Forever blocks in Scratch


Repeat until blocks in Scratch
Until the Boolean statement is true, the code inside the Repeat until block will keep going in a loop. Once it’s false, whatever code comes after that gets executed. So basically: Keep doing something until a certain point!

Repeat until blocks in Scratch

What is the deal with conditional statements in Scratch?

Remember these biggies: Operators help you make conditional statements and return a Boolean output. Here’s a breakdown of the different ones you should know:

conditional statements in scratch

Smaller number:
Have you got something smaller than the other? The block will let you know if it’s true or not. Numbers and letters can all be used in this block. For example, notes like ‘a are worth less than letters like ‘z.’ So if that first one is less, the block gives you a heads-up by returning true. But if it isn’t smaller, don’t worry – it’ll come back false.

Greater Than:
If value 1 is more prominent than value 2, this block gives an actual back; anything else, it’s not good news and returns false.

Equal To:
Is it the same, or isn’t it? This block will tell you whether value one and value 2 are the same deal – just be sure not to switch up your case!

Both Boolean blocks must return true to get a sweet true from this one. One’s false? Better luck next time.

Like adventure? You can have them sometimes with this block even when one of them’s false – as long as one comes through triumphant with a true, you get one too!

Got some boolean but want the opposite of what it has to say? This lousy boy swaps that out for you with its verdict – does da boolean equal false? Then you’ve got yourself a true.

How do I use conditional statements in Scratch?
Let’s take a look at an example. Say we want to make a program that shows students their grades based on marks. Here are the guidelines:
● Marks – Grades
● 81-100 – A
● 61-80 – B
● 41-60 – C
● 33-40 – D
● 0-33 – E
Solution: Before tackling coding in Scratch, let’s lay out a plan by creating a flowchart. That way, we’ll be one step ahead of the game!

conditional statements in scratch

You must set up the program’s two variables, Marks and Grades. The flag is a Boolean that tracks whether marks were entered. You know the drill, the values must be between 0 and 100. Once everything’s initialized, the script can start running!
So you’ve got the Scratch Cat as the sprite for the project. Here’s how to write this script: if-else and if-then-else Conditional statement in scratch example time! Let’s get started.

1 – When you open Launch mBlock, remember to save it if you’re already working on a project. Then head over to the ‘New’ tab and get crackin’!

2 – From The Sprite library, go through Scratch Cat attire for Sprite import.

3 – Black Hat’s drag and drop for Script’s execution.

4 – Three Variables: A – Number for first marks, B – letter for second grade, C – To flag a boolean.

5 – Initializing all variables!

6 – Use repeat till () block to ensure the user’s entering legit marks. Then, set variable Flag to 0 (or false) before anyone enters anything. That way, it looks at the input at least once. If someone tries funny business with their marks, you’ll know immediately.

7 – After setting up the loop, ask the user for their marks and put them in the Marks variable. Pretty easy. Let’s move on.

8 – Figure out what counts as a passing grade. See, if the marks are under 33, then you can quickly check that by using the () () (less than) operator block — if it’s true or false. And once you’ve checked that, if it’s true, set the grade to E and tell the user to change their ‘Flag’ to one, which means they passed!

9 – Follow the same above step for other grades.

conditional statements in scratch


Scratch is an excellent language for young kids. Conditional statements in Scratch are super user-friendly, with clear instructions for saving and sharing files. Scratch coding is  simpler than Python programming but still gives you the basics of coding so you can learn without getting frustrated. Thank goodness there are options like this to keep up with our tech-crazed world! You can also learn scratch coding yourself.

Scratch programming for kids not only prepares them for careers as professional programmers, but also nurtures the development of a new generation of creative, systematic thinkers who are comfortable using programming to express their ideas. Codingal offers the best online coding course for kids. Try a free class today.

Best Coding Course for K12 Kids
FAQs on Conditional Statement In Scratch!

1 – What do conditional statements in Scratch do?
They help guide you along. For example, a Boolean condition supplied by you (the programmer) will tell the lizard brain built into your game whether it’s time to move forward or not. Pretty cool.

2 – What statements can you use to make conditional statements in Scratch -speak?
Well, if you’re looking to draw a branching path, your choices come down to an if-else or an if then else. So that’s the two big ones you need to know!

3 – In Scratch, what’s with the whole loop thing?
It’s repeating a task if certain conditions are met. Ta-da! So yeah, that’s the basics of it.




Sign up to our newsletter

Get the latest blogs, articles, and updates delivered straight to your inbox.

Share with your friends

Try a free class