Operators:
It is hard to describe theoretical syntax that why we start from middle, but on examples everything will be clear.
Assignment
First operator is assignent which assing value to variable. Below some examples with comments
a = 1; //assign integer '1' to variable 'a'
b = 2.0; //assing float point value to variable 'b'
name = "John Lenon"; //assign string 'John Lenon' to variable 'name'
birthday = 1980.12.01; //assing date 1st dec 1980 to variable 'birthday'
Arithmetic
Another basic operations like addition, subtraction, multiplication and division for numeric
variables with simple examples below.
c = a + 2; //addition
d = 1 - 3; //substraction
e = d / c; //division
f = e * 1; //multiplication
There is also one arithmetic operator (+
) for string
types to make string operation simpler. Below example.
firstname = "John";
lastname = "Lenon";
hello = "Hello " + firstname + " " + lastname;
//value of hello string is 'Hello John Lenon'
Bitwise Operators
Bitwise operations like AND
, OR
can be use only with logical
types. Below basic operation examples
a = false;
b = a AND true; // b => false
c = true AND true; // c => true;
d = a OR true; // d => true;
e = true AND true; // e => true;
Comparison Operators
Comparition operators =
, !=
can be used on any variables, but >
, >=
, <
, <=
should be use only with numeric
variables as others are unable to compare like in line 7
a = 1 = 2; // a => false
b = 1 != 2; // b => true
c = 2 < 2; // c => false
d = 2 <= 2; // d => true
e = 3 > 1; // e => true
f = "John" != "john"; // f => true
g = "John" > "john"; // f => don't know.
Incrementing/Decrementing Operators
There are also two special operators for incrementing (++
) or decrementing (--
) values. Of course, you can use is only with numeric
values
a = 1;
a++; // a is equal 2 now
a--; // a is equal 1 again