Programming Operators

Operators in Scratch

This chapter will teach you the Scratch tools you wish to write programs that compare values, evaluate logical expressions, and make decisions supporting the results. We’ll also bear several valuable examples of applications. Here’s what you’ll learn along the way:

  •  Basic problem-solving techniques.
  • The way to use them if and if/else blocks to decide among alternative actions.
  • The way to construct logical expressions to judge given conditions.
  • The flow of control in branching statements.

The programs we’ve written to this point follow a straightforward execution model. They start with the primary instruction, execute it, go on to the subsequent education, and then on until they reach the tip of the program. The command blocks of those programs are executed in sequence, with no skipping or jumping.

However, you’ll want to change this sequential flow of program execution in many programming situations. For example, suppose you wrote an application to tutor children in basic arithmetic. In that case, you’d like to execute certain blocks to reward correct answers and a different set of blocks for wrong answers (to reveal the correct answer or offer another chance, for example). Then, your script can decide what to try and do next by comparing the student’s input with the correct answer. This is often the idea of all decision-making tasks.

In this blog,

We’ll explore the decision-making commands available in Scratch and write several programs that use these commands to check
inputs and perform different actions.

First, I’ll introduce you to Scratch’s comparison operators and show how you can use them to match numbers, letters, and strings. Then, I’ll introduce the if and if/else blocks and explain their crucial role in decision-making. You’ll also find out how to check multiple conditions using nested if and if/else blocks and write a menu-driven program to place these blocks into action. After that, I’ll introduce logical operators as others, thanks to testing multiple conditions. Finally, in the last section, we’ll write several exciting programs that support all of the concepts you’ve learned.

What is meant by Operator??

Scratch includes a large number of operators. An operator is a symbol that tells the computer to perform certain operations on data. For example, they manipulate constants and variables and form expressions. The data items that operators act upon are called operands. Some operators need two operands, while others require only one operand.

The types of operators are:

  1. Arithmetic operator
  2. Relational/Comparison Operator
  3. Logical Operators

Comparison Operator:

You make decisions daily, and every decision typically leads you to perform specific actions. you’ll think, for example, “If that car is a smaller amount than $2,000, I’ll decrease.” You then ask about the car’s price and judge whether or not you wish to shop for it.

You can make decisions in Scratch, too. For example, you can use comparison operators to compare the values of two variables or expressions to determine whether one is more prominent than, less than, or adequate to the opposite. Comparison operators test the relationship between two values. That’s why they are also called relational operators. You can see the three relational operators supported in Scratch.
Logical -Operators in Scratch
Logical -Operators in Scratch

Note that the blocks in the above Table all have a hexagonal shape. As you might recall from the previous post, the results of evaluating one amongst these blocks could be a Boolean value, which may be either true or false. Because of this reason, these expressions are called Boolean expressions. For example, the expression “price < 2 000” evaluates if the value of the variable price is more minor than 2,000. If the price value is smaller than 2,000, the block returns true; otherwise, it returns false. You’ll use this expression to construct your decision condition within the form, “If (price < 2000), then buy the car.”

Before we glance at the if block, which allows you to implement such a test, let’s check an easy example illustrating how Boolean expressions are evaluated in Scratch.

Conclusion

Comparison Operator or Relational Operator means, Sometimes we need to compare two quantities, and depending on their relation, we make a specific decision. There are three relational operators in Scratch.

  1. Equals to

  2. Greater Than

  3. Small than

We can find many projects developed by students, teachers, and experts on scratch.com. 

Logical operators in scraych3.0

Related post.

Scratch programming examples for beginners.

Easy games to create on Scratch step-by-step

Botley 2.0 Review – Techniques to use it.

Extensive Review Beebot: Let’s know, our little friend.