What Are the Conditional Statements in Scratch? | Event Operators in Scratch

Updated By

Reviewed By

Contents
scratch games

Scratch conditional statements determine whether a Boolean condition supplied by the programmer is true or false. They enable you to compare a variable to another variable or test a variable against a value, allowing you to control how the program behaves depending on whether the condition is satisfied or not. Control or Conditional statements on Scratch provide the software with a tone of power and enable it to perform a wide range of tasks, such as building straightforward calculators and operating robots.

In this article, we will explain everything about conditional blocks on Scratch and their uses of the same. Scroll down to find out more.

What Are Conditional Statements?

To understand conditional statements in Scratch, we will take the example of a bulb. When the switch is off, you turn on the bulb; however, if it doesn’t operate when the switch is on, you should either replace it or check the connection. You react in accordance with the circumstances or demands.

A flowchart can illustrate the same concept

Conditional Statements in Scratch

Flowcharts are employed when creating and describing straightforward processes or programs. They help in understanding a process by aiding in the visualization of what is occurring. They may also help in the discovery of defects, bottlenecks, and other less obvious aspects of the process. It is advised that you create a flowchart before you begin writing the script.

What Are Conditional Statements in Scratch?

The conditional statements on Scratch are given below:

1. IF Then () Block in Scratch

if() then is a control block on Scratch. The block will evaluate its Boolean state. If the condition set is true, then the block will be executed. Here the condition will be evaluated only once. However, if the condition is set to false while executing the program, then the code will be running until it is true.

if then block

2. IF Then Else () Block in Scratch

If Then Else is a control block on Scratch. To put it in other words, we can say that the If Then Else block is the extension of the If Then block. Similar to the If () Then block, if the condition is true, the code in the first C (space) will be executed, and the script will then continue. If the condition is false, the second C’s code will execute. The block will evaluate its Boolean state.

if then else block

Other Control Blocks in Scratch

A few other control blocks in Scratch programming language are explained below:

Repeat Block in Scratch

This block contains blocks that will loop a predetermined number of times before allowing the script to proceed. A decimal is entered, and the result is rounded up.

repeat block

Forever Block in Scratch

Similar to the Repeat () block and the Repeat Until () block, blocks held inside of this block will be in a loop, except that the loop never ends (unless the stop sign is clicked, the Stop All block is activated, or the stop script block is activated within the loop). The block has no bump at the bottom because of this infinite loop; otherwise, the blocks below it would never be triggered.

forever block

Repeat Until Block in Scratch

If the supplied Boolean statement is true, the blocks contained within this block will loop until the code below the block (if any), if any, will execute.

repeat until block

Project– If the supplied Boolean statement is true, the blocks contained within this block will loop until the code below the block (if any), if any, will

What are Operators in Scratch?

Let’s take a closer look at a few crucial operators that are used to create conditional statements and produce Boolean results before moving on. The list and purpose of the operators are listed below:

Operators in Scratch
  • Less Than: If the first value is less than the second value, the block verifies this. The block returns true if it is less; if not, it returns false. Along with using numbers, this block also functions with letters. Letters in the beginning of the alphabet, such a, b, and c, are worth less in Scratch than letters at the end (e.g. x, y, z).
  • Greater Than: The block determines whether the first value exceeds the second value. The block returns true if the second value is less; else, it returns false.
  • Equal To: The block determines whether the first value and the second value are equal. The block returns true if the values are equal; false otherwise. No regard is given to case in this block.
  • And: The block combines two Boolean blocks, therefore for it to return true, both of them must be true. The block returns true if they are both true; false if any or none of them are true.
  • Or: The block unites two Boolean blocks so that either one of them must be true in order for it to return true; if neither of them is true, the block returns false.
  • Not: The block determines whether the Boolean contained within it is false; if it is, it returns true; if it is true, it returns false.

How To Use Conditional Statements in Scratch? – Example

Let us create a Scratch program which displays the grades of the students according to the marks. The rules are given below:

  • Marks – Grades
  • 81-100 – A                                                     
  • 61-80 – B                                                     
  • 41-60 – C                                                      
  • 33-40 – D                                                    
  • 0-33 – E                                                     

Solution: We will need two variables named Marks and Grade to store the marks and the grade. You can see from the flowchart that we want the programme to run until the user enters legitimate marks, which are scores between 0 and 100. Another variable, Flag, a Boolean, will be required to track whether the user has submitted legitimate marks or not. At the start of the script, all three variables need to be initialized.

If Else Statement and If Then Else Statement Example

For this project, the Scratch Cat will serve as the sprite.

To write the script, follow these instructions:

  • Launch mBlock; if it’s already running and you’re working on a project, save it. then select New.
  • Have the sprite import the Scratch Cat attire from the Sprite Library.
  • Drag and drop a hat block to begin the script’s execution.
  • Make three variables: a-number, first marks, b-Letter in second grade, c-Flag a Boolean
  • Initialize each and every variable. (The initial value of the flag is zero, or False)
  • We want to keep asking the user to enter marks until it is valid, as was mentioned. The repeat till () block is helpful in this situation. To assess if the marks entered are legitimate or not, the variable Flag will be used. As the code inside the block should run at least once at startup, Flag should be zero, or false, when no input is entered.
  • As in the tutorial on variables and operator blocks, after entering the loop, we will prompt the user to enter the marks and save it in the Marks variable.
  • Now we must determine the range of the markings. Therefore, to check the range, we will use another if block and other conditional blocks. Let’s check, for instance, if Marks are fewer than 33. If the condition is true or false, we can check it using the () () (less than) operator block. If the claim is accurate, we will set the grade to E, let the user know, and alter the Flag to one, meaning true.
  • For other grades, follow step 8 in a similar manner.

To execute the script, click on the green flag and to halt the script, click on the red octagon next to the green flag.

FAQs on Conditional Statements in Scratch

What is conditional statements in Scratch?
Conditional statements in Scratch determine whether a Boolean condition supplied by the programmer is true or false.

What statements are used as conditional statements in Scratch?
If Else and If then else are the two conditional statements used in Scratch programming language.

How many conditional blocks are available in Scratch?
There are 5 conditional blocks in Scratch; Repeat, Forever, If then, If else, Repeat until.

What is a conditional loop in Scratch?
A loop in Scratch means it contains a condition to repeat a task.

Scratch is a simple language to navigate. It has an easy to use desktop with very clear and direct instructions for actions like saving and sharing. Compared to an interpreted language like Python, Scratch is a lot easier and definitely an option for children who wish to dip their toes into coding and such computer languages. In today’s world where computer technology is advancing by leaps and bounds, such easy-to-use and accessible languages are extremely helpful and a good starting point for children to introduce themselves to interpreted languages.

Get 1-on-1 online Scratch classes

Related Posts

Programming Tools in Scratch

Programming Tools in Scratch

Programming Tools in Scratch: Scratch is a visual programming language developed by the Lifelong Kindergarten Group at the MIT Media Lab. It allows users to

Do you want to learn from the top 1-on-1 tutors?

Concepts | Test-prep | Homework help

4.6/5

4.8/5