NUM_I + (2 * NIM_J)
Expressions that use Boolean operators return the values TRUE or FALSE. Well know Boolean operators include:
Ada encoding | |
---|---|
Equals | = |
Not equals | /= |
Less than | < |
Greater than | > |
Less than or equal to | <= |
Greater than or equal to | >= |
Logical and | and |
Logical or | or |
Logical not | not |
The first 6 of the above are sometimes referred to as comparison or relational operators and the remaining 3 as logical operators. Examples of Boolean expressions:
A_VALUE < 50 B_VALUE = 0 X_VALUE >= 10 and X_VALUE <= 20 X_VALUE < 10 or X_VALUE > 20 A_VALUE < 20.0 and (B_VALUE /= 'q' or testFun(A_VALUE, C_VALUE) = 1)
These can be interpreted as follows:
Level | Operator |
---|---|
2 | +, - (unary plus and minus) |
3 | ** (exponential) |
4 | *, /, rem, mod |
5 | +, - |
6 | Comparison operators |
7 | Logical not |
8 | Other logical operators |
9 | := (assignment) |
The order of execution of operators on the same level is controlled by associativity:
If an operator is non-associative it cannot be used in a sequence.
Note on rem and mod operators.
Statements are the commands in a language that perform actions and change the "state" (the term is used for historical reasons). The state of a program is described by the values held by its variables at a specific point during its execution. Example statements:
Statements are usually separated by some operator (symbol), in Ada this is the semi-colon character (;).
NUMBER := 2;
Thus, in Ada if we wish to use two operands each of a different type in an expression we must convert one of the operands so that its type is equivalent to that of the other. Remember Ada type conversions have the following form:
T(N)
Program constructs are program statements which are used to control the order (flow) in which statements are executed (or not executed). There are a number of recognised basic program constructs that can be classified as follows:
To which we can also add routine invocation. Note also that each of the above constructs are all also program statements in their own right.
A sequence construct tells the processor which statement is to be executed next. By default, this is the statement following the current statement (or the first statement in the program). In the early days of computing, if we wished to "jump" to some statement other than the following statement a "goto" construct was used. This is still supported by Ada, however, its usage is considered to be bad practice as it makes it difficult to "trace" a program's execution and to determine the state of variables at a given point during processing. As a result errors are often obscure and difficult to locate. For this reason "goto" statements should be avoided. In most cases we can use a procedure or function call (i.e. routine invocation) instead.
Created and maintained by Frans Coenen. Last updated 11 October 1999