The basic operation behind any program is evaluation. In nearly every program you make, you will need to include expressions that need to be evaluated. These expressions form the basis of most every program written.
When an expression is evaluated, it can yield either "true" or "false," called "Boolean values," or it can yield a number. These answers are then used as directions for the next step in the program.
To write an expression, you need to be aware of the operators used in common programming languages. Operators are ways of indicating relationships using symbols. Here are a few you are probably already familiar with:
In the examples below, the arrow symbol ( => ) indicates the answer given by Flash when the given expression is evaluated.
| Name | Symbol | Description | Example(s) |
|---|---|---|---|
| Addition | + | Indicates that two values should be added together. | 2 + 2 => 4 1 + 3 => 4 |
| Multiplication | * | Indicates that values should be multiplied together. | 2 * 2 => 4 1 * 3 => 3 |
| Greater Than | > | Shows a relationship between two values. (Notice that this yields a 'true' or 'false' answer.) |
2 > 1 => true 1 > 2 => false |
| Equals | = | This symbol assigns value to a variable. If it succeeds in assigning value to a variable, the entire expression yields a true value. | someVariable = 3 => true |
There are many other operators used in programming. Below are a few of the more commonly used ones.
| Name | Symbol | Description | Example(s) |
|---|---|---|---|
| Less than or equal to | <= | This is used in comparison between two factors. It yields a 'true' value if the preceeding value is less than or equal to the following one. | 1 <= 3 => true 2 <= 1 => false 2 <= 2 => true |
| Equality (is same as) |
== | The two values are compared with this operator. If the values are the same, a 'true' value is returned. This operator is different from equals, which is used to assign value. | 2 == 2 => true 4 == 1 => false |
| NOT (not same as) |
!= | The two values are compared with this operator. If the values are different, a 'true' value is returned. This can be somewhat confusing because it yields a true when the values are not the same. | 2 != 2 => false 4 != 1 => true |
| AND (are both true) |
&& | This operator makes TWO sets of comparisons, and if they are BOTH true, returns a true value. | (2 == 2) && (4 > 3) => true
(2 == 1) && (4 > 3) => false (2 == 2) && (4 < 3) => false (2 == 1) && (4 < 3) => false |
| OR (one is true) |
|| | This operator makes TWO sets of comparisons and if at least one of them is true, returns a true value. | (2 == 2) || (4 > 3) => true
(2 == 1) || (4 > 3) => true (2 == 2) || (4 < 3) => true (2 == 1) || (4 < 3) => false |
| NOT (is not true) |
! | This operator is a little confusing. When an expression bearing this operator is evaluated, if the expression IS NOT TRUE, it yields a true value; if the expression IS TRUE, it yields a false value. | !(2 == 2) => false
!(2 == 1) => true !(4 < 3) => true |