Operators
Operators operate!
Just like a doctor operates, an operator cuts stuff in half or thirds and stitches stuff together. For instance, a division operator takes a number and divides it into pieces. An addition operator takes one thing a stitches it to another. These are two operators you learned form grade school, but look at the list below!:
Here is the list of operators:
++(Pre or post increment)
--(Pre or post decrement)
!(Logical Not-true into false and false into true)
~(Binary Not)
*(Multiply)
/(Divide)
%(Modulo-Returns the remainder of a division)
+(Add numbers or append strings)
-(Subtract)
<<(Binary shift left)
>>(Binary shift right)
>>>(Binary unsigned shift right)
<(Less than)
>(Greater than)
<=(Less than or equal to)
>=(Greater than or equal to)
&(Binary And)
|(Binary Or)
^(Binary Exclusive Or)
&&(Logical And-True if both conditions are true)
||(Logical Or-True if either condition is true)
==(Equals)
===(Strictly equals-Limited type conversion)
!=(Not equals)
!==(Strictly not equals)
?:(Conditional)
+=(Add and assign)
-=(Subtract and assign)
*=(Multiply and assign)
/=()Divide and assign
&=(Binary And and assign)
|=(Binary Or and assign)
^=(Binary exclusive Or and assign)
<<=(Binary shift left and assign)
>>=(Binary shift right and assign)
>>>=(Binary unsign shift right and assign)
Boring!
I didn’t write that stuff.
So,that list is rather complicated looking, and as of now I will not bother to tell you what each one does, but lets look at the operators we know:
+(plus)
-(minus)
*(times)
/(divided by)
=(equals)
%(percent of)
1+1=2
6-3=3
3*3=9
12/4=3
25%100=25
That makes sense, right? But what is:
cat+dog ?
cat+dog= catdog
This is what it means when it says that the + operator appends strings (remember that strings are letters that are strung together). Look at this example:
Example1
var gato:String="cat";
var perro:String="dog";
trace(gato+perro);
//catdog
Look at this one:
Example2
var gato:String="cat";
var perro:String="dog";
trace(gato+perro+gato+perro);
//catdogcatdog
Adding some more to the second example:
if(perro=="cat"){trace("perro is cat")}
else{trace(“perro is not cat”);}
Now, I want to tell you something very important about the == and the = operators. The == can be read “is”, the = can be read as “equals.” The normal = sign sets something equal to something else, but the == sign checks to see if is something is something else.
Check out the Conditionals and Loops tutorials for more info on other operators.