2 using labels in the case statement, 2 selection statements, 1 the maxl if statement – ElmoMC Multi-Axis Motion Controller-Maestro User Manual

Page 87

Advertising
background image

5.5.1.2

5.5.2.1

Maestro

Software Manual

MAXL Program Language

MAN-MASSW (Ver. Q)

Using Labels in the case Statement

Labels that appear after the case keyword cannot also appear outside a switch
statement. (This restriction also applies to the otherwise keyword.) The following
code fragment shows the correct use of case labels:

Syntax

case (expression)

Example:

switch( cmd )
case(1) //begin motion
axis.bg
case(2) // motor On

axis.mo = 1

case(3) // motor Off

axis.mo = 0

otherwise // get motor status
cmd

=

axis.ms

end switch

5.5.2

Selection Statements

The MAXL selection statements, if and switch, provide a means to conditionally
execute sections of code.

Syntax

selection-statement

:

if (

expression

)

statement

end [ if]

if (

expression

)

statement

else

statement

end [ if]

switch (

expression

)

statement

end [ switch ]

The MAXL if Statement

The if statement evaluates the expression enclosed in parentheses. The expression
must be an arithmetic type. In both forms of the if syntax, if the expression evaluates
to a nonzero value (true), the statement dependent on the evaluation is executed;
otherwise, it is skipped. In the if...else syntax, the second statement is executed if the
result of evaluating the expression is zero.

Syntax

if ( expression ) statement end [ if]

if ( expression ) statement else statement end [ if]

Example:

if (b == 4 )
if( c == 18 )
a=1 // b is 4; c is 18
else
a=2 // b is 4; c isn`t 18
end if
else
a=3 // b isn`t 4;
end if

5-25

Advertising