What is Conditional Programming in Scratch?
Last Updated :
07 Aug, 2021
Scratch is a high-level visual programming language tool that interacts with users through diagrams and blocks that have the basics of a program inbuilt in it. Scratch is used to make interactive programs especially for kids using the block kind of interfaces so that they can easily learn languages and it is free to use. In this article, we will learn about coordinates and conditionals.
Coordinates System
In Scratch, the coordinate system is used to locate the sprite(actor if the scene) on the screen or we can say that the coordinate system is a mathematical grid with infinite values. It is a two-dimensional cartesian coordinate system and is used to allocate a point/object or to extract the position of the object/point.
Position: Coordinate system has two coordinates, i.e., X position and Y position to find the position of the sprite on the screen. Here, X position denotes the horizontal location of the sprite and the Y position denotes the vertical location of the sprite. The X position can range from 240 to -240, where 240 is the rightmost side of the stage or screen and -240 is the leftmost, and the Y position ranges from 180 to -180, where 180 is the topmost side and -180 is the bottom-most side. and coordinates can be written as (X, Y). For example, (3, 4) is the coordinate of a sprite on the stage.
To change the backdrop of the scratch to a xy-grid. In the bottom right corner of the screen, click on the "backdrop" option to choose the x-y coordinate system as background.
There will be numerous lists of backdrops that scratch offers as shown below:
Now, choose the "xy grid" backdrop and you will observe that the background of sprite changes to xy grid. This xy grid gives an exact idea of the minimum, maximum, and centre values of the x and y coordinate. When the sprite is moved from one place to another, the corresponding x, y coordinate is also shown simultaneously. This is depicted in the above gif.
The X position and Y position of a sprite can be determined, set, and changed by using the motion block. Below are the ways in which the coordinate of a sprite can be modified.

Conditionals in scratch
Conditional statements have conditions and the programs flow based on the true or false value of the condition. They are found in the control programming blocks as shown below.
Here, if() then and if() then else are the conditional blocks.
1. if() then block
It is a control block. This block works on the condition's value. If the condition is true, then the set of code is executed else nothing happens. Here, the condition is only checked once, and if the condition is changed to false while the script is running, then the script will keep running until it is finished. It is just like the if-else statement in languages like Java, Python, etc. Let's understand this concept by making a small project. Let us understand the working of the wait block with the help of a simple project. In this project, if the user types "a", then the sprite must glide for 1 second.
Procedure:
Step 1: Click on event block and choose 1st control block denoting start of the program(drag it to center).
Step 2: Click on control block and drag if then block below the above step.
Step 3: Go to the sensing block and drag key space pressed and place it inside the condition of if-then block and change "space" to "a"
Step 4: Go to motion block and drag glide 1 sec to random position inside if-then block.
Step 5: Now, run the program.
Below is the implementation of the above procedure.

2. if-then-else
It is a control block. This block is an extension of the if-then value. If a condition is true, then a set of lines gets executed. If a condition is false, then else part is executed. Let us understand the working of the wait block with the help of a simple project. In this project, if the user types "a", then the sprite must glide for 1 second, else the sprite must say "hello".
Procedure:
Step 1: Click on event block and choose 1st control block denoting the start of the program(drag it to center).
Step 2: Click on the control block and drag if then block below the above step.
Step 3: Go to the sensing block and drag key space pressed and place it inside the condition of if then block, change "space" to "a"
Step 4: Go to motion block and drag glide 1 sec to a random position, inside the if then block.
Step 5: Go to looks block and drag say hello block inside else part.
Step 6: Now run the program
Below is the implementation of the procedure:
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read