Expression
From SwinBrain
An expression is an instruction or set of instructions that result in a value of a certain type.
The following are examples of expressions:
| Expression | Description |
|---|---|
| 10 | The integer value 10. |
| true | A Boolean expression. |
| x > 10 | A Boolean expression that will return true if x is larger than 10. |
| x | The value of the x variable, the type is determined by the type of the variable x. |
| 10 + 1 | An arithmetic equation resulting in an integer value. |
| (10 + 1) / 2.5 + 3 * 2.1 | An arithmetic equation resulting in a real (or double) value. |
| GetX() | A call to the function GetX, the type of value is determined by the return type of GetX. |
| x + 10 | An arithmetic equation using the variable x. The type of this expression is determined by the type of x. |
| CalculateArea(radius) | A call to the function CalculateArea passing in the parameter radius. The type of this expression is based upon the return type of the CalculateArea function. |
Expressions are used within statements. For example
- The assignment statement in Pascal is variable := expression,
- In C# an if statement is if(boolean-expression) statement ;