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
What is Conditional Programming in Scratch?
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
5 min read
What is Iteration in Scratch Programming?
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
7 min read
Condition Handling in R Programming
Decision handling or Condition handling is an important point in any programming language. Most of the use cases result in either positive or negative results. Sometimes there is the possibility of condition checking of more than one possibility and it lies with n number of possibilities. In this ar
5 min read
Introduction to Scratch Programming
Scratch is a block-based visual programming language that can be used to make interactive games and animations. It has a huge online community where you can share, discuss and view scratch programs. The objective behind the development of Scratch is to help children(mostly) to think creatively, work
3 min read
Introduction to Scratch Programming
Scratch is an event-driven visual programming language developed by MIT. In Scratch, we can create our own interactive stories, games, and animations using building blocks. In this platform, we do not need to write code to perform operations, things are done just by drag and drop, just like visual b
5 min read
Ask(), Wait() and Answer() Block in Scratch Programming
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
4 min read
Conditional Operator in Programming
Conditional Operator, often referred to as the ternary operator, is a concise way to express a conditional (if-else) statement in many programming languages. It is represented by the "?" symbol and is sometimes called the ternary operator because it takes three operands. Table of Content Syntax of C
9 min read
What is a Block in Programming?
In programming, a block is a set of statements that are grouped and treated as a single unit. Blocks are used to define the scope of variables, control the flow of execution in conditional statements and loops, and encapsulate code in functions, methods, or classes. Table of Content What is a Block
6 min read
Script in Scratch Programming
Scratch is an event-driven programming tool developed by the Lifelong Kindergarten group at MIT in the media lab to create your own games, visual programs, interactive stories using building blocks. To create a program in Scratch we do not need to write code to perform operations. In Scratch, the op
4 min read
Variables in Scratch Programming
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
7 min read
Basics of Scratch Programming
Scratch is a programming language. Programming language is meant that a means of communicating with the computer, so as to give some instructions for it to perform. Programming in Scratch is very easy, including animation and games. It is a very useful tool for young kids or creators to learn and im
6 min read
Control flow statements in Programming
Control flow refers to the order in which statements within a program execute. While programs typically follow a sequential flow from top to bottom, there are scenarios where we need more flexibility. This article provides a clear understanding about everything you need to know about Control Flow St
15+ min read
Goto Statement in Programming
Goto statement is a control flow statement present in certain programming languages like C and C++. It enables programmers to transfer program control to a labeled section of code within the same function or block. Despite its availability, its usage is often discouraged in modern programming practi
3 min read
What is Imperative Programming?
The computer programming paradigm defines the style of programming, approach to solve problem and method of computer systems towards providing solutions use programming. There is a classification of programming paradigms into two broad paradigms i.e., imperative and declarative. This article is base
6 min read
Conditional Statements in Programming | Definition, Types, Best Practices
Conditional statements in programming are used to control the flow of a program based on certain conditions. These statements allow the execution of different code blocks depending on whether a specified condition evaluates to true or false, providing a fundamental mechanism for decision-making in a
15+ min read
goto statement in R Programming
Goto statement in a general programming sense is a command that takes the code to the specified line or block of code provided to it. This is helpful when the need is to jump from one programming section to the other without the use of functions and without creating an abnormal shift. Unfortunately,
2 min read
If statement in Programming
An if statement is a fundamental control structure in programming languages that allows you to execute specific code blocks based on whether a condition is true or false. It is used to make decisions and control the flow of execution in your program. Table of Content What is an If Statement?Example
9 min read
What are inline conditional expressions in ReactJS ?
In React conditional rendering is the process of showing components based on a particular condition. With inline conditional expression in React, we can write the condition in a single line. For example, While building the to-do list app, developers should show a task only if any pending task is ava
4 min read
Iteration Statements in Programming
Iteration statements, commonly known as loops, are statements in programming used to execute part of code repeatedly based on condition or set of conditions. These constructs are important for performing repetitive tasks efficiently. In this article, we will discuss various types of iteration statem
5 min read