An operator in Euphoria will perform an action between two or more operands on both sides. Euphoria Programming is a simple and flexible language that also provides a robust pool of operators to help developers achieve a lot. These operators are bundled into four major types, namely:
These operators are used to carry out simple algebra and arithmetic computations. They are used to evaluate mathematical operations. They are listed and explained below. For the examples, let x
be 10, and y
be 30.
Addition operator (+
): It adds two operand values, (x+y gives 40)
.
Subtraction operator (-
): It subtracts the value of the right operand from the left, (y-x gives 20)
.
Division operator (/
): It divides the operand on its left side with that on its right side. (y/x gives 3)
Multiplication operator (*
): It multiplys both operands, (x*y gives 300)
.
Unary minus(-) and unary plus(+): They operate only on a single operand, the one that comes after it from the left to right direction. For example, (-y gives -30 while +x gives +10)
. They indicate if a value is positive(+) or negative (-).
These operators compare the operands at their left and right sides and then decide. Let’s look at the various comparison operators used in Euphoria:
Equal (=): It checks for equality between the operands’ left and right sides. If equality exists, it evaluates to true. For example, (10=30 gives false)
.
Not equal (!=): It checks if the operands are not equal in value and if not equal, it returns true. Otherwise, it returns false, (10!=30 gives true).
The greater than >
: It compares the operand on its left with the right. It returns true if the left operand is greater
in value than the right. Otherwise, it returns false
. For example, (10>30 returns false)
.
The less than (<): It returns true if the value on the right side is less than the value on the left side. For example, (x<y returns true)
.
Less or equal to (<=
): It checks if the value of the left operand is less than or equal to the value of the right operand, if yes then the condition becomes true, (10<=30 returns true)
.
Greater or equal to (>=
): It checks if the value of the left operand is greater than or equal to the value of the right operand, if yes then the condition becomes true
. If not, the condition evaluates false
. For example,(10 >= 30 returns false)
.
These operators carryout out logic on operands in an expression and make a decision based on the output which is usually boolean.
true
if any of the operands have non-zero values and evaluates to false
only if both operands are zero values.NOT Y
, will make Y
false
, if it was originally true
.This set of operators assigns whatever is on its right to its left. This is true for the simple assignment operator(=
). For example,
name = "jane"
this will automatically make name
to have the value of jane
.
Other not so simple assignment operators are also available. These are not so simple because they are combined with any of the arithmetic operators. This makes them evaluate the expression first before assigning the result to the left operand. These operators include:
+=
)-=
)/=
)*=
)&=
)Note: The
&=
operator assigns to the left operand an ANDED value of the operand on the left and the one on the right. For example:X &= Y
is the same asX = X & Y
.
Euphoria also has an operator for concatenation. The &
operator is used to concatenate or join two objects. These joined objects will have the sum of the two joining objects as their length.
sequence x, y, z
x = {4, 5, 6}
y = {7}
z = {4, 5, 6} & {7}
print(1,z)
This produces the output: {4,5,6,7}
--declare the variables sequence x, y, z --assign values to the declared variables x = {4, 5, 6} y = {7} --concatenate the x and y values z = {4, 5, 6} & {7} -- print the concatenated values print(1,z)
In the above, we see the concatenation operator &
is used to join the two sequences x
and y
to produce another sequence z
. It is the same as the length of the two sequences joined together.
RELATED TAGS
CONTRIBUTOR
View all Courses