2 the maxl switch statement – ElmoMC Multi-Axis Motion Controller-Maestro User Manual

Page 88

Advertising
background image

5.5.2.2 The MAXL switch Statement

The MAXL switch statement allows selection among multiple sections of code,
depending on the value of an expression.

The switch statement causes an unconditional jump to, into, or past the statement that
is the “switch body,” depending on the value of the controlling expression, the values
of the case labels, and the presence or absence of a otherwise label.

The switch body is normally a compound statements (although this is not a syntactic
requirement). Usually, some of the statements in the switch body are labeled with case
labels or with the otherwise label. Labeled statements are not syntactic requirements,
but the switch statement is meaningless without them. The otherwise label can appear
only once.

Syntax

switch ( expression ) case-statements end [ switch ]
case-statements:

case (expression) statements

otherwise statements

The expression in the case label is converted to the type of the controlling expression
and is then compared for equality. The behavior is shown in the table below.

Table 5-5 Table Switch Statement Behavior

Condition

Action

Converted value matches that of the
promoted controlling expression.

Control is transferred to the
statement following that label.

None of the constants match the constants
in the case labels; otherwise label is
present.

Control is transferred to the
otherwise label.

None of the constants match the constants
in the case labels; otherwise label is not
present.

Control is transferred to the
statement after the switch
statement.

A switch statement can be nested. In such cases, case or otherwise labels associate
with the most deeply nested switch statements that enclose them. For example:

switch( attribute_type)
case (1) // Object attribute is command.
switch( cmdName)

case (1) // Begin motion command.Axis.bg

case( 2) // Motor On command.
Axis.mo=1
end switch
case (3) // Object attribute is method.
...

Maestro

Software Manual

MAXL Program Language

MAN-MASSW (Ver. Q)

5-26

Advertising