beautypg.com

Conditions and comparison operators – Multichannel Systems Roboocyte2 JavaScript Manual User Manual

Page 3

background image

The other operators are shortcuts for:

x += 2;

is equal to

x = x + 2;

x -= 2;

is equal to

x = x – 2;

x *= 2;

is equal to

x = x * 2;

x /= 2;

is equal to

x = x / 2;

Conditions and comparison operators
Comparison operators are normally used with conditional statements. By using these (with keywords

if

and

else

) you can execute different parts of the script depending on certain conditions. A condition

statement is started with the keyword

if

, followed by a condition expression within parenthesis and

statements within a block (within {}). It can optionally be followed by an

else

statement.

if (condition)
{
statements1
}

or

if (condition)
{
statements1
}
else
{
statements2
}

Conditional statements can also be nested:

if (condition1)
{


if (condition2)
{

statements

}

}

The condition is usually a comparison expression. Comparison operators are

Operator Description

Example

==

equal

x == 2

!=

not equal

x != 2

>

greater

x > 2