[Next] [Prev] [Right] [Left] [Up] [Index] [Root]
Conditional Expression

Conditional Expression

A conditional expression is an 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 conditional expression is the value of the expression after `select'. If the condition is false, then the value of the conditional expression is the value of the expression after `else'.

Conditional 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] [Right] [Left] [Up] [Index] [Root]