<< Chapter < Page Chapter >> Page >

An operator that operates on one operand is called a unary operator. An operator that operates on two operands is called a binary operator. An operator that operates on three operands is called a ternary operator.

Some operators can be either unary or binary

Some operators can behave either as a unary or as a binary operator in languages such as Java and C#. The best-known operator that can behave either way in those languages is the minus character (-).

As a binary operator, the minus character causes its right operand to be subtracted from its left operand. For example, the third statement belowsubtracts the variable y from the variable x and assigns the result of the subtraction to the variable z . After the third statement is executed, the variable z contains the value 1.

  • x = 6;
  • y = 5;
  • z = x - y;

The minus character as a unary operator

As a unary operator, the minus character causes the algebraic sign of the right operand to be changed. For example, the second statement belowcauses a value of -5 to be assigned to (stored in) the variable x .

  • y = 5;
  • x = -y;

Binary operators use infix notation

To keep you abreast of the current jargon, binary operators in Scratch always use infix notation. This means that the operator appears between its operands.

Some other programming languages have unary operators that use prefix notation and postfix notation. For prefix notation, the operator appears before (to the left of) its operand. For postfix notation, the operator appears after (to the right of) its operand.

General behavior of an operator

As a result of performing the specified action, an operator can be said to return a value (or evaluate to a value) of a given type. The type of value returned depends on the operator and the type of the operands.

To evaluate to a value means that after the action is performed, the operator and its operands are effectively replacedin the expression by the value that is returned.

Operator categories

There are many different kinds of operators. Therefore, the easiest way to study them is to divide them into categories such as the following

  • arithmetic
  • relational
  • logical
  • bitwise
  • assignment

This module will concentrate on arithmetic operators. Future modules will deal with other kinds of operators.


In this module, I will present and explain a Scratch program named Arithmetic01 . This program illustrates the use of the following arithmetic operators (see the bottom script in the rightmost panel of Image 4 ):

  • + (addition)
  • - (subtraction)

Variables with the following names are created and displayed on the stage (see Image 5 ):

  • LeftOperand - has a slider
  • RightOperand - has a slider
  • Sum
  • Diff

In addition, a button is displayed on the stage.

The user adjusts the values of the LeftOperand and RightOperand variables with a pair of sliders. When the user clicks the button, the variablenamed Sum displays the sum of the values of the left and right operands. The variable named Diff displays the result of subtracting the right operand from the left operand.

Discussion and sample code

I'm going to walk you through the steps required to develop this program, being brief on those things that you already know about and being more verboseon the new material.

Questions & Answers

who was the first nanotechnologist
Lizzy Reply
technologist's thinker father is Richard Feynman but the literature first user scientist Nario Tagunichi.
Norio Taniguchi
I need help
anyone have book of Abdel Salam Hamdy Makhlouf book in pdf Fundamentals of Nanoparticles: Classifications, Synthesis
Naeem Reply
what happen with The nano material on The deep space.?
pedro Reply
It could change the whole space science.
the characteristics of nano materials can be studied by solving which equation?
sibaram Reply
plz answer fast
synthesis of nano materials by chemical reaction taking place in aqueous solvents under high temperature and pressure is call?
hydrothermal synthesis
how can chip be made from sand
Eke Reply
is this allso about nanoscale material
are nano particles real
Missy Reply
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
Lale Reply
no can't
where is the latest information on a no technology how can I find it
where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
Application of nanotechnology in medicine
has a lot of application modern world
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
yes that's correct
I think
Nasa has use it in the 60's, copper as water purification in the moon travel.
nanocopper obvius
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
STM - Scanning Tunneling Microscope.
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now

Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?