[Next] [Prev] [_____] [Left] [Up] [Index] [Root]
The select expression

The select expression

A select-expression is a conditional expression whose value depends on the truth-value of a Boolean expression. Its syntax is:

    CONDITION select EXPRESSION else EXPRESSION

If the condition is true, then the value of the select-expression is the value of the expression after `select'. If the condition is false, then the value of the select-expression is the value of the expression after `else'.

These expressions may be used like any other expressions. They can be particularly convenient within set or sequence constructors.

For information about the full conditional statement, see The if statement.

Example

> j := -57;
> k := j ge 0 select j else -j;
> print k;
57

> prime := [ IsPrime(n) select "yes" else "no" : n in [1..80] ]; > print prime; [ no, yes, yes, no, yes, no, yes, no, no, no, yes, no, yes, no, no, no, yes, no, yes, no, no, no, yes, no, no, no, no, no, yes, no, yes, no, no, no, no, no, yes, no, no, no, yes, no, yes, no, no, no, yes, no, no, no, no, no, yes, no, no, no, no, no, yes, no, yes, no, no, no, no, no, yes, no, no, no, yes, no, yes, no, no, no, no, no, yes, no ] > print prime[51]; no

[Next] [Prev] [_____] [Left] [Up] [Index] [Root]