v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha
v10.50 v10.55 Alpha v10.54 Alpha v10.53 Alpha v10.52 Alpha v10.51 Alpha

Expressions

An expression is a statement that calculates a value. The simplest type of expression is assignment:

x = 2

The expression x = 2 calculates 2 as the value of x.

All expressions contain operators, which are described in Operators. Operators indicate how an expression should be evaluated in order to arrive at its value. For example

x + 2

says to add2 to x to find the value of the expression. Another example is

x > 2

which indicates that x is greater than 2. This is a Boolean expression, so it will evaluate to either true or false. Therefore, if x = 3, then x > 2 will evaluate to true; if x = 1, it will return false.

True is denoted by a non-zero integer (any integer except 0), and false is a zero integer (0). True and false are also supported for lists (an empty list is false, while all others are true), and strings (an empty string is false, while all others are true), and null is considered false. However, all Boolean operators will result in integer values.

Select expression

The select expression selects the value to which it evaluates based on Boolean expressions. This is the format for a select expression:

C++
select {
  <expression1> : <statement1>
  <expression2> : <statement2>
  ...
};

The expressions are evaluated in order, and the statement that is associated with the first true expression is executed. That value is what the entire expression evaluates to.

C++
x = 10
Value_of_x = select {
x < 5 : "Less than 5";
x >= 5 : "Greater than or equal to 5";
};

The above expression will evaluate to “Greater than or equal to 5” because the first true expression is x >= 5. Note that a semicolon is required at the end of a select expression because it is not a compound statement and can be used in an expression context.

There is also a keyword default, which in effect always evaluates to true. An example of its use is

C++
Astring = select { 
A == 1 : "one"; 
A == 2 : "two";
A == 3: "three";
A > 3 : "overflow";
default : null;
};

If none of the first four expressions evaluates to true, then default will be eval- uated, returning a value of null for the entire expression.

Select expressions can also be used to conditionally execute statements, similar to C switch statements:

C++
select {
A == 1 : DoSomething();
A == 2 : DoSomethingElse();
default: DoNothing();
};

In this case the appropriate function is called depending on the value of A, but the evaluated result of the select expression is ignored.