beautypg.com

1 select expression, 1 selec – Teledyne LeCroy Protocol Analyzers File-Based Decoding User Manual User Manual

Page 14

background image

Chapter 3: Expressions

File-based Decoding User Manual

8

LeCroy Corporation

3.1 select expression

The select expression selects the value to which it evaluates based on Boolean

expressions. This is the format for a select expression:

select {

:
:
...

};

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.

x = 10
Value_of_x = select {

x < 5 : "Less than 5";
x >= 5 : "Greater than or equal to 5";

};

The above expression evaluates 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

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 is evaluated,

returning a value of null for the entire expression.
select expressions can also be used to conditionally execute statements, similar to C
switch statements:

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.