A computer running through a program always has exactly one concern: "Where is my next instruction?" In most cases, the next instruction will be right after the current instruction. This is the sequential structure.
A "statement" is nothing more than an instruction telling the computer to do one thing. A program is simply telling the computer to do lots of "one thing"s.
The most basic statement is as follows:
;
A semicolon indicates the end of a statement. Therefore, the above statement does absolutely nothing.
The next simplest statement is this:
return;
A "return" statement returns the program to the verb that called it. You don't need to concern yourself with the true meaning of this yet, but keep this in mind: wherever "return" is encountered in a program, the program will immediately end.
The simplest statement you will use most often is assignment:
location = value;
If you read the variable lesson, you've already seen plenty of assignments. location can be either an object's property or a variable. value is any value at all, or an operation that returns, or calculates, a value. For instance:
result = 5 + 4;
"result" is a variable, a location in memory. "5 + 4" is an addition operation, and it will return the value 9. The value 9 will be stored in "result".
An operator is a symbol that will take one or more values, perform some sort of calculation with them, then return some result. You know what most of them do just by looking at them.
There are three types of operators:
Math Operators
Operation | Symbol | Syntax |
Assignment | = | location = value |
Addition | + | value1 + value2 |
Subtraction | - | value1 - value2 |
Multiplication | * | value1 * value2 |
Division | / | value1 / value2 |
Modulus | % | value1 % value2 |
Exponent | ^ | value1^value2 |
Negative | - | -value |
Comparison Operators
Operation | Symbol | Syntax |
Equality | == | value1 == value2 |
Inequality | != | value1 != value2 |
Less Than | < | value1 < value2 |
Greater Than | > | value1 > value2 |
Less Than or Equal To | <= | value1 <= value2 |
Greater Than or Equal To | >= | value1 >= value2 |
Logical Operators
Operation | Symbol | Syntax |
And | && | value1 && value2 |
Or | || | value1 || value2 |
Not | ! | !value1 |
Don't be worried if you don't understand boolean values or the logical operators. These are explained in the decision structures lesson.